Remove the first word in a Python string?

后端 未结 4 1759

What\'s the quickest/cleanest way to remove the first word of a string? I know I can use split and then iterate on the array to get my string. But I\'m pretty s

4条回答
  •  粉色の甜心
    2020-12-25 11:08

    Presuming you can guarantee the words are separated by a single space, str.partition() is what you are looking for.

    >>> test = "word1 word2 word3"
    >>> test.partition(" ")
    ('word1', ' ', 'word2 word3')
    

    The third item in the tuple is the part you want.

提交回复
热议问题