the*_*ter -1 python string replace
感谢这个网站上的答案我现在知道你可以通过字符串[: - 1]删除字符串的最后一个字符,这真的很有帮助,但是我需要能够删除第一个以及据我所知这个技术这不可能.那么有没有其他方法来删除部分字符串而不替换特定字母?
你的意思是"这是不可能的"?:)
使用Explain Python的切片表示法完全可以:
>>> mystr = 'abcde'
>>> mystr[1:] # Remove the first
'bcde'
>>> mystr[1:-1] # Remove the first and the last
'bcd'
>>> mystr[2:-2] # Remove the first two and the last two
'c'
>>>
Run Code Online (Sandbox Code Playgroud)