日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程语言 > python >内容正文

python

python strip() 函数探究

發(fā)布時(shí)間:2025/3/20 python 16 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python strip() 函数探究 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

strip()方法語法:str.strip([chars]);

聲明:str為字符串,rm為要?jiǎng)h除的字符序列

  • str.strip(rm) 刪除字符串中開頭、結(jié)尾處,位于rm刪除序列的字符
eg1: #首尾端'0'被刪除,中間不動(dòng) >>> t='0000this is string example0000wow!!!0000' >>> t.strip('0') 'this is string example0000wow!!!' eg2: #無入?yún)?#xff0c;默認(rèn)刪除首尾所有空字符 ‘\n\t空格‘ >>>s='\n 0000this is string example0000wow!!!0000\n \t' >>> s.strip() '0000this is string example0000wow!!!0000'
  • str.lstrip(rm) 刪除字符串中開頭處,位于 rm刪除序列的字符
''' 遇到問題沒人解答?小編創(chuàng)建了一個(gè)Python學(xué)習(xí)交流QQ群:579817333 尋找有志同道合的小伙伴,互幫互助,群里還有不錯(cuò)的視頻學(xué)習(xí)教程和PDF電子書! ''' t='0000this is string example0000wow!!!0000' >>> t.lstrip('0') 'this is string example0000wow!!!0000' #空入?yún)⑼瑯涌蓜h除首部空字符,'.rstrip()'同理 s='\n 0000this is string example0000wow!!!0000\n \t' >>> s.lstrip() '0000this is string example0000wow!!!0000\n \t'
  • str.rstrip(rm) 刪除字符串中結(jié)尾處,位于 rm刪除序列的字符
t='0000this is string example0000wow!!!0000' >>> t.rstrip('0') '0000this is string example0000wow!!!'s='\n 0000this is string example0000wow!!!0000\n \t' >>> s.rstrip() '\n 0000this is string example0000wow!!!0000'

究竟何為’首尾’?實(shí)驗(yàn)之

''' 遇到問題沒人解答?小編創(chuàng)建了一個(gè)Python學(xué)習(xí)交流QQ群:579817333 尋找有志同道合的小伙伴,互幫互助,群里還有不錯(cuò)的視頻學(xué)習(xí)教程和PDF電子書! ''' s='\n 0000this is string is example0000wow!!!0000\n \t' >>> s.lstrip('\n 0') 'this is string is example0000wow!!!0000\n \t' #首部'\n 0000'被刪除>>> s.lstrip('\n 0this') 'ring is example0000wow!!!0000\n \t'

奇妙啊,我的目標(biāo)是刪除首部’\n 0000this’,結(jié)果’\n 0000this is st’全被刪除,說明:符合入?yún)?’\n 0this’)的字符皆是刪除對(duì)象,不論字符順序

但,為何string后面的is沒有刪除?因?yàn)?#xff0c;'首部’指的是’連續(xù)符合’入?yún)⒁蟮淖址?#xff0c;string中的’r’隔斷了入?yún)⒌倪B續(xù)字符要求,python判定首部結(jié)束。

實(shí)驗(yàn)證明:

所謂的首、尾,判定依據(jù)是-是否連續(xù)符合入?yún)⒁?如果符合,不論順序,皆可操作,一直到遇到第一個(gè)非入?yún)⒆址麨橹?

總結(jié)

以上是生活随笔為你收集整理的python strip() 函数探究的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。