python去掉字符串中空格的方法
1.strip():把头和尾的空格去掉
2.lstrip():把左边的空格去掉
3.rstrip():把右边的空格去掉
4.replace('c1','c2'):把字符串里的c1替换成c2。故可以用replace(' ','')来去掉字符串里的所有空格
5.split():通过指定分隔符对字符串进行切片,如果参数num 有指定值,则仅分隔 num 个子字符串
In[2]: a=' ddd dfe dfd efre ddd '
In[3]: a
Out[3]: ' ddd dfe dfd efre ddd '
In[4]: a.strip()
Out[4]: 'ddd dfe dfd efre ddd'
In[5]: a.lstrip()
Out[5]: 'ddd dfe dfd efre ddd '
In[6]: a.rstrip()
Out[6]: ' ddd dfe dfd efre ddd'
In[7]: a.replace(' ','')
Out[7]: 'ddddfedfdefreddd'
In[8]: a.split()
Out[8]: ['ddd', 'dfe', 'dfd', 'efre', 'ddd']
6.使用正则表达式
re.split(r'\s+', 'a b c')
['a', 'b', 'c']
python去掉字符串中空格的方法的更多相关文章
- Python关于去除字符串中空格的方法
		
Python关于去除字符串中空格的方法 在编写程序时我们经常会遇到需要将字符串中的空格去掉的情况,通常我们可以使用下面几种解决方法: 1.strip()方法:该方法只能把字符串头和尾的空格去掉,但是不 ...
 - Java中去除字符串中空格的方法
		
昨天写了一个关于Excel文件处理的脚本,在字符串匹配功能上总是出现多余不正确的匹配,debug调试之后,发现一个坑. ------->代码中字符串使用了replaceAll()方法,去除了所有 ...
 - python去掉字符串中重复字符的方法
		
If order does not matter, you can use foo = "mppmt" "".join(set(foo)) set() ...
 - 去除字符串中空格的方法(2016.1.12P141-2)
		
// forif来处理空格 // 方法一 String str = " ww sse rr"; String str1;// 定义一个中间变量 String str2 = &quo ...
 - python清除字符串中间空格的方法
		
1.使用字符串函数replace >>> a = 'hello world' >>> a.replace(' ', '') 'helloworld' 看上这种方法真 ...
 - python去除字符串中间空格的方法
		
1.使用字符串函数replace a = 'hello world' a.replace(' ', '') # 'helloworld' 2.使用字符串函数split a = ''.join(a.sp ...
 - Python: 去掉字符串中的非数字(或非字母)字符
		
>>> crazystring = ‘dade142.;!0142f[.,]ad’ 只保留数字>>> filter(str.isdigit, crazystring ...
 - Python中常见字符串去除空格的方法总结
		
Python中常见字符串去除空格的方法总结 1:strip()方法,去除字符串开头或者结尾的空格>>> a = " a b c ">>> a.s ...
 - python文本 去掉字符串前后空格
		
python文本 去掉字符串前后空格 场景: 去掉字符串前后空格 可以使用strip,lstrip,rstrip方法 >>> a="abc".center (30 ...
 
随机推荐
- python收集jvm数据
			
之前前辈用 java 写的收集 jvm 脚本, 不太方便组内小伙伴维护, 遂用 python 重写了 #!/usr/bin/env python # -*- coding: utf-8 -*- # F ...
 - Python数据结构:栈 队列
			
栈,队列的特性: 1.栈(stacks)是一种只能通过访问其一端来实现数据存储与检索的线性数据结构,具有后进先出(last in first out,LIFO)的特征 2.队列(queue)是一种具有 ...
 - docker学习实践之路[第三站]node站点部署
			
拉取node镜像 docker pull node 定制Dockerfile文件 FROM node EXPOSE ENTRYPOINT [ "node", "/www/ ...
 - (转)实现一个cache装饰器,实现过期可清除功能
			
原文:http://www.cnblogs.com/JerryZao/p/9574927.html http://blog.51cto.com/11281400/2107790-----装饰器应用练习 ...
 - (转)python通过paramiko实现,ssh功能
			
python通过paramiko实现,ssh功能 1 import paramiko 2 3 ssh =paramiko.SSHClient()#创建一个SSH连接对象 4 ssh.set_missi ...
 - Element ui tree结合Vue使用遇到的一些问题(一)
			
下图是一个后台管理系统,展示的是角色列表 当我点击编辑的时候,弹出一个模态框,如下图 功能需求:点击编辑按钮,弹出模态框,选择权限那块,默认选中当前角色拥有的权限. 问题:第一次点击编辑按钮时,不会选 ...
 - SpringCloud入门之eclipse新建maven子项目和聚合项目
			
一.new maven project : next 二.勾选 create a simple project : next 三.Group Id:项目的包路径 如com.test,之后创建的C ...
 - 【IT笔试面试题整理】给定二叉树,给每层生成一个链表
			
[试题描述]定义一个函数,给定二叉树,给每层生成一个链表 We can do a simple level by level traversal of the tree, with a slight ...
 - [机器学习] 训练集(train set) 验证集(validation set) 测试集(test set)
			
在有监督(supervise)的机器学习中,数据集常被分成2~3个即: 训练集(train set) 验证集(validation set) 测试集(test set) 一般需要将样本分成独立的三部分 ...
 - docker-compose部署elk+apm
			
1.安装docker 参考我的另外的一篇博客:https://www.cnblogs.com/cuishuai/p/9485939.html 2.安装docker-compose # yum -y i ...