How to split a string into a list?

后端 未结 9 2459
执念已碎
执念已碎 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:23

    Splits the string in text on any consecutive runs of whitespace.

    words = text.split()      
    

    Split the string in text on delimiter: ",".

    words = text.split(",")   
    

    The words variable will be a list and contain the words from text split on the delimiter.

提交回复
热议问题