python清除字符串中间空格的实例讲解
作者:yesNow_xiao 时间:2023-12-29 22:40:24
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
来源:https://blog.csdn.net/depers15/article/details/52223956
标签:python,字符串,空格
0
投稿
猜你喜欢
python opencv鼠标画点之cv2.drawMarker()函数
2021-11-28 18:34:40
Python处理PPT文件的实用知识点总结
2021-04-26 04:11:10
HTML5拿什么取代Flash?
2010-05-10 20:37:00
LRUCache的实现原理及利用python实现的方法
2022-06-26 06:51:51
Javascript中常见的逻辑题和解决方法
2024-05-22 10:31:21
go sync.Once实现高效单例模式详解
2024-02-05 05:49:37
python中if-elif-else语句实例用法讲解
2023-03-08 21:59:05
Python 中的异步 for 循环示例详解
2021-07-09 10:27:30
PHP模拟asp中response类实现方法
2024-06-05 09:39:32
pytorch 实现张量tensor,图片,CPU,GPU,数组等的转换
2023-08-12 07:44:34
python的等深分箱实例
2022-11-30 01:01:20
Python中摘要算法MD5,SHA1简介及应用实例代码
2023-12-12 00:36:41
Python 反转输出正整数的操作
2021-05-04 18:37:16
Python面向对象中类(class)的简单理解与用法分析
2021-01-05 00:07:37
Python使用requests及BeautifulSoup构建爬虫实例代码
2021-08-13 11:33:13
Centos7.3下mysql5.7.18安装并修改初始密码的方法
2024-01-20 00:02:11
ASP六大对象介绍
2007-09-08 12:28:00
基于javascript实现表格的简单操作
2024-04-30 08:55:24
Python实现将照片变成卡通图片的方法【基于opencv】
2023-06-08 11:32:54
Python压缩模块zipfile实现原理及用法解析
2023-07-13 03:01:46