我可以删除数字,但不能删除字母字符:
>>> text
'132abcd13232111'
>>> text.strip('123')
'abcd'
为什么以下不起作用?
>>> text.strip('abcd')
'132abcd13232111'
原因很简单,在的文档strip:
str.strip([chars])
Return a copy of the string with the leading and trailing characters removed.
The chars argument is a string specifying the set of characters to be removed.
'abcd'
既不是字符串的前导,也不是尾随'132abcd13232111'
所以它没有被剥夺。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)