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

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條評論
主站蜘蛛池模板: 黄色短视频在线播放 | 91精品久久久久含羞草 | 精品人人做人人爽久久久 | 青草青视频在线观看 | 久久国产精品一区二区三区 | 亚洲欧美日韩国产专区一区 | 99视频福利 | 四虎精品影院永久在线播放 | 99综合在线| 免费亚洲网站 | 色综合综合色综合色综合 | 四虎影视在线影院4hutv | 亚洲免费在线观看视频 | 午夜性色福利视频在线视频 | 精品国产一区二区 | 久久久久久综合七次郎 | 欧洲国产伦久久久久久久 | 成人影视在线观看 | 成人国产激情福利久久精品 | 成人影院一区二区三区 | 久久亚洲国产 | 激情小视频在线播放免费 | 国产精品香蕉一区二区三区 | 国产农村妇女一级毛片 | 无遮挡又黄又爽又色的视频免费 | 久久艹在线观看 | 国产精品大片天天看片 | 日日夜夜天天干干 | 一级毛片不收费 | 日本一区二区三区不卡在线视频 | 久久福利一区二区三区 | 中文字幕精品一区二区三区在线 | 色综合天天综合网国产成人 | 黄黄的网站在线观看 | 91精品一区二区 | 精品视频一区二区三三区四区 | 国产欧美亚洲精品第一区 | 97视频免费人人观看人人 | 日本天天色| 91精品国产免费久久国语麻豆 | 天天爽夜夜爽免费看 |