python去除字符串中间空格的四种方法
1.用replace函数。
用法:原字符串.replace('需要替换的内容','替换后的内容'),详见:http://www.21fanqie.com/thread-208-1-1.html
2.用split先断开,再合上。
用法:'需要加入的字符'.join(原字符串.split('需要断开的位置'))
str ='导演: 奥利维·那卡什 ... 2011 法国 剧情 喜剧'
print(','.join(str.split(' ')))
3.用.strip(),比如:title= data.text.strip(),详见:http://www.21fanqie.com/thread-208-1-1.html
4.用正则表达式http://www.360doc.com/content/14/0514/10/16740871_377457822.shtml
|