In this post we will be creating a Python script that will split an existing string in to a list of words. To do this we will be using the ‘split()’ method which will break a string down in to a list with multiple items. The split method can contain a delimiter or can be left empty and by default it will split at the occurrence of any whitespace.
See below our string for this example.
string = "Hello how are you"
To split the string in to a list of words we would use the following code.
string = "Hello how are you" words = string.split() print(words)
The above would return the following as output.
['Hello', 'how', 'are', 'you'] >>>