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

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條評論
主站蜘蛛池模板: 精品无人区乱码1区2区3区在线 | 酒色网站 | 狠狠色官网在线 | 久久在线免费 | 99热久久这里只精品国产9 | 免费视频不卡一区二区三区 | 国产精品久久久亚洲第一牛牛 | 亚洲欧美日本在线 | 亚洲欧美中文字幕专区 | 日韩中文字幕推理片 | 波多野结衣乳巨码无在线观看 | 最猛黑人xxxⅹ黑人猛交 | 2021最新国产成人精品视频 | 亚洲免费在线看 | 精品一久久香蕉国产线看观看下 | 在线99热 | 天天综合天天做天天综合 | 欧美久久久久久 | 亚洲精品久久久久影院 | 中文字幕色婷婷在线精品中 | 99热福利 | 在线小视频国产 | bbw老妇bbwbbwass| 米奇7777 | 日韩欧美网 | 亚欧成人毛片一区二区三区四区 | 香蕉国产一区二区 | 成人在线第一页 | 久热这里只有精品在线 | 夜夜撸天天操 | 日日操夜夜骑 | 欧洲成人免费高清视频 | 久久www成人看片 | 日韩欧美网站 | 国产成人91精品 | 九九视频在线观看视频23 | 午夜视频www | 999久久久精品视频在线观看 | 久久99国产综合精品 | 奇米影视盒7777 | 日韩亚洲视频 |