Fix Python – How do I split a string into a list of words?

Question

Asked By – Thanx

How do I split a sentence and store each word in a list? For example, given a string like "these are words", how do I get a list like ["these", "are", "words"]?

Now we will see solution for issue: How do I split a string into a list of words?


Answer

Given a string sentence, this stores each word in a list called words:

words = sentence.split()

This question is answered By – nstehr

This answer is collected from stackoverflow and reviewed by FixPython community admins, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0