Python, how to create a list from a string

This is how you can create aListFrom aStringIn Python.

First, you need to determine how to cut the string. For example, there is a space every time.

You passed' 'Word separatorsplit()The methods provided by each Python string.

example:

phrase = 'I am going to buy the milk'
words = phrase.split(' ')

print(words) # [‘I’, ‘am’, ‘going’, ‘to’, ‘buy’, ‘the’, ‘milk’]


More python tutorials: