How to split a string into a list?

后端 未结 9 2460
执念已碎
执念已碎 2020-11-21 04:32

I want my Python function to split a sentence (input) and store each word in a list. My current code splits the sentence, but does not store the words as a list. How do I do

9条回答
  •  情书的邮戳
    2020-11-21 05:24

    text.split()
    

    This should be enough to store each word in a list. words is already a list of the words from the sentence, so there is no need for the loop.

    Second, it might be a typo, but you have your loop a little messed up. If you really did want to use append, it would be:

    words.append(word)
    

    not

    word.append(words)
    

提交回复
热议问题