2013-12-13 99 views
-1

感谢这个网站上的答案我现在知道你可以通过字符串[: - 1]删除字符串的最后一个字符,但这真的很有帮助,但我需要为了能够消除第一个,并据我了解这种技术,这是不可能的。那么还有其他方法可以在不替换特定字母的情况下删除部分字符串吗?我如何删除字符串的第一个字符[python]

回答

5

你是什么意思“这是不可能的”? :)

这是完全可能的Explain Python's slice notation

>>> 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' 
>>> 
1

string[1:]

您可能需要阅读一些文档。 :)

相关问题