44问答网
所有问题
如何用python replace字符串中间多余的空格转换为一个空格
如题所述
举报该问题
推荐答案 2017-10-17
# 不推荐
while ' ' in the_str:
the_str = the_str.replace(' ', ' ')
其实可以用正则。
温馨提示:答案为网友推荐,仅供参考
当前网址:
http://44.wendadaohang.com/zd/VWVZZDKZZD3DVY6ZYG.html
相似回答
python
3去除
字符串
(
string
)
空格
的五种方法
答:
1、strip方法去掉字符串两边(开头和结尾)的空格
2、lstrip方法去掉字符串左边的空格 3、rstrip方法去掉字符串右边的空格 4、replace方法替换字符串的空格为空 注意: 这里说一下replace方法的具体用法 old_str:原字符串需要替换的内容,new_str:将old_str替换成的内容,max:代表替换的次数,默认全部...
python
去除
字符串
中
的空格
答:
用
replace
函数:your_str.replace(' ', '')a = 'hello word' # 把a
字符串
里的word替换为
python
a.replace('word','python') # 输出的结果是hello python用split断开再合上:''.join(your_str.split())用正则表达式来完成替换:import re strinfo = re.compile('word')b = strinfo.sub...
python中
,
如何
将
字符串
中的多个不等量
空格
改为改为逗号分隔?
答:
1、创建
python
代码,testsplit.py;2、定义测试
字符串
,不等量空格分隔的字符串;str='1 2 3 4 5 6 7'3、把str中
的空格
分开,以','进行拼接;p=','.join(str.split())print(p)4、查看运行结果,为‘1,2,3,4,5,6,7’;
Python
爬虫获得IP地址后,
字符串
内有
空格
,
如何
去除空格,并且每个ip末 ...
视频时间 206:99
大家正在搜
python替换字符串中的空格
python字符串去除多余的空格
python把空格替换成字符串
python字符串删除指定字符串
python去除字符串前后空格
python字符串去除两端空格
python中空格算字符吗
python replace用法
Python把字符串去掉空格
相关问题
如何用python replace字符串中间多余的空格转换为...
如何用python replace字符串中间多余的空格转换为...
python中,如何将字符串中的多个不等量空格改为改为逗号分...
如何用python replace字符串中间多余的空格转换为...
如何用python replace字符串中间多余的空格转换为...
Python如何将字符串中的符号都换为空格?
python 里面怎么提取 空格分开的字符串
如何去除字符串中的多余空格