亚洲免费在线-亚洲免费在线播放-亚洲免费在线观看-亚洲免费在线观看视频-亚洲免费在线看-亚洲免费在线视频

Python去除字符串兩端空格的方法

系統 2013 0

目的

  獲得一個首尾不含多余空格的字符串

方法

可以使用字符串的以下方法處理:

string.lstrip(s[, chars])
Return a copy of the string with leading characters removed. If chars is omitted or None, whitespace characters are removed. If given and not None, chars must be a string; the characters in the string will be stripped from the beginning of the string this method is called on.

string.rstrip(s[, chars])
Return a copy of the string with trailing characters removed. If chars is omitted or None, whitespace characters are removed. If given and not None, chars must be a string; the characters in the string will be stripped from the end of the string this method is called on.

string.strip(s[, chars])
Return a copy of the string with leading and trailing characters removed. If chars is omitted or None, whitespace characters are removed. If given and not None, chars must be a string; the characters in the string will be stripped from the both ends of the string this method is called on.

?

具體的效果如下:

復制代碼 代碼如下:

In [10]: x='???? Hi,Jack!??????? '

In [11]: print '|',x.lstrip(),'|',x.rstrip(),'|',x.strip(),'|'
| Hi,Jack!???????? |????? Hi,Jack! | Hi,Jack! |

其中提供的參數chars用來刪除特定的符號,注意空格并沒有被移除,例如:

復制代碼 代碼如下:

In [12]: x='yxyxyxxxyy Hello xyxyxyy'

In [13]: print x.strip('xy')
?Hello


更多文章、技術交流、商務合作、聯系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號聯系: 360901061

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對您有幫助就好】

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長會非常 感謝您的哦!!!

發表我的評論
最新評論 總共0條評論
主站蜘蛛池模板: 久久99爰这里有精品国产 | 精品久久洲久久久久护士免费 | 狠狠狠地在啪线香蕉 | 尹人综合网 | 国产91久久久久久久免费 | 2021久久精品99精品久久 | 青草福利 | 手机看片一区 | 高清不卡在线 | 午夜激情婷婷 | 国产一级视频 | 国产精品高清在线观看地址 | 亚洲 欧美 另类 天天更新影院 | 亚洲欧美成人永久第一网站 | 奇米第 | 天天干天天色天天射 | 999精品影视在线观看 | 亚洲精品成人a在线观看 | 天天摸天天干天天操 | 国内免费一区二区三区视频 | 日本大蕉香蕉大视频在线观看 | 一区二区视频在线观看免费的 | 天天操天天搞 | 四虎永久精品免费网址大全 | 国产热re99久久6国产精品 | 久久91精品久久91综合 | 福利视频网| 免费毛片大全 | 欧美日韩视频精品一区二区 | 亚洲波多野结衣日韩在线 | 精品久久久久久婷婷 | 深夜福利免费观看 | 亚洲成人性视频 | 新26uuu在线亚洲欧美 | 四虎最新在线 | 天堂精品在线 | 香蕉久久久久 | 四虎视频国产在线观看 | 在线观看自拍视频 | 亚洲一区二区三区91 | 中文字幕不卡在线高清 |