python清除字符串中间空格的方法
2024-10-20 01:40:10
1、使用字符串函数replace
>>> a = 'hello world'
>>> a.replace(' ', '')
'helloworld'
看上这种方法真的是很笨。
2、使用字符串函数split
>>> a = ''.join(a.split())
>>> print(a)
helloworld
3、使用正则表达式
>>> import re
>>> strinfo = re.compile()
>>> strinfo = re.compile(' ')
>>> b = strinfo.sub('', a)
>>> print(b)
helloworld
最新文章
- JAVA EE Hibernate基础一之环境配置
- c#设计模式之简单工厂
- springmvc中RequestMapping的解析
- 在SQL Server 2012中实现CDC for Oracle
- Delphi 的字符及字符串[5] - 字符串与 Windows API
- Druid:一个用于大数据实时处理的开源分布式系统
- 免费web直接打印的控件PAZU
- Datatable转换成List实体对象列表 几个实例
- IE,火狐,谷歌浏览器下js判断滚动条是否已拉到页面最底部
- poj 1011 Sticks (DFS+剪枝)
- 提高duilib的richedit控制的一些特征
- Hadoop学习之配置Eclipse远程调试Hadoop
- 16个必须熟悉的linux服务器监控命令
- 从构建分布式秒杀系统聊聊WebSocket推送通知
- TensorFlow走过的坑之---数据读取和tf中batch的使用方法
- (27)session(设置值、取值、修改、删除)
- windows.onload和body的onload属性的区别
- php导出excel不知道列数 php26进制函数
- Event Tracing For Windows
- CasperJS API中文博客链接