strip()函数用法


strip的意思是剥夺。

strip()函数作用是操作字符串。

按一定规则剥夺字符串内容,移除头尾,不移除中间。

strip([chars])函数参数是字符序列,注意:字符序列。

1 - strip()不传参

str = '     helloworld     '
print(str.strip())

运行结果:

helloworld

2 - strip()传一个字符

str = '009876000dfd7647000000'
print(str.strip('0'))

运行结果:

9876000dfd7647

3 - strip()传一个字符序列

str = '12sdfjladsjfalksdjw12'
print(str.strip('1w2'))

运行结果

sdfjladsjfalksdj

头尾只要有字符序列内字符,都去掉。


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM