python - 删除 Python 字符串中的第一个单词?

标签 python string

删除字符串的第一个单词的最快/最干净的方法是什么?我知道我可以使用 split 然后迭代数组来获取我的字符串。但我很确定这不是最好的方法。

Ps:我对python很陌生,我不知道每一个技巧。

提前感谢您的帮助。

最佳答案

我认为最好的方法是拆分,但通过提供 maxsplit 将其限制为仅拆分一次参数:

>>> s = 'word1 word2 word3'
>>> s.split(' ', 1)
['word1', 'word2 word3']
>>> s.split(' ', 1)[1]
'word2 word3'

关于python - 删除 Python 字符串中的第一个单词?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12883376/

相关文章:

适用于 Windows 的 python os.mkfifo()

string - 在 Prolog 中将列表元素更改为带空格的字符串

c - 如何比较 C 字符串中的子字符串和解析数字

c# - foreach 循环中一串单词的 ToUpper 方法不起作用

python DBF : 'ascii' codec can't decode byte 0xf6 in position 6: ordinal not in range(128)

python 列表/序列格式

python - 元音索引 : Python error "' in <string >' requires string as left operand, not int"

比较字符串

python - 两台计算机之间的套接字编程

python - 如何调整 xmlrpclib 来解释自定义类型?