欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

python清除字符串中間空格的實(shí)例講解

 更新時(shí)間:2018年05月11日 15:05:50   作者:yesNow_xiao  
今天小編就為大家分享一篇python清除字符串中間空格的實(shí)例講解,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧

1、使用字符串函數(shù)replace

>>> a = 'hello world'
>>> a.replace(' ', '')
'helloworld'

看上這種方法真的是很笨。

2、使用字符串函數(shù)split

>>> a = ''.join(a.split())
>>> print(a)
helloworld

3、使用正則表達(dá)式

>>> import re
>>> strinfo = re.compile()
>>> strinfo = re.compile(' ')
>>> b = strinfo.sub('', a)
>>> print(b)
helloworld

以上這篇python清除字符串中間空格的實(shí)例講解就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論