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

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條評論
主站蜘蛛池模板: 四虎在线免费观看 | avtt亚洲一区中文字幕 | 99国产精品高清一区二区二区 | 99精彩免费观看 | 2020国产成人免费视频 | 在线观看视频亚洲 | 波多野结衣3女同在线观看 波多野结衣av1区2区3区 | 日本精品视频一视频高清 | 国产欧美亚洲精品综合在线 | 国产成人精品亚洲77美色 | 国产精品一级香蕉一区 | 成人在线激情视频 | 欧美一级特毛片 | 久久不卡影院 | 国产欧美日韩亚洲 | 99re8免费视频精品全部 | 国产高清精品自在线看 | 我要看欧美一级毛片 | 日日操美女 | 凹凸精品视频分类国产品免费 | 精品国产九九 | 狠狠色狠狠色综合 | 91亚洲国产成人久久精品网站 | 中文字幕日本在线 | 激情五月婷婷红人馆 | 久久精品亚洲日本筱田优 | 日本在线不卡免 | 日韩欧美伊人久久大香线蕉 | 久久精品久 | 亚洲一区二区三区高清 | 成人午夜性视频欧美成人 | 亚洲性生活视频 | 国产香蕉精品视频在 | 久久99热精品免费观看k影院 | 中文字幕在线视频一区 | 日本波多野结衣在线 | 国产自产拍精品视频免费看 | 999毛片| 久操中文在线 | 国产福利第一视频 | 国产日韩欧美亚洲 |