How to Convert a String to a List
To convert a string to a list, you can use the split()
method in Python. It splits the string at the specified separator and returns a list.
Example: Converting a String to a List
# Converting a string to a list
text = "Python is fun"
word_list = text.split() # Splits by spaces by default
print(word_list)
Output
["Python", "is", "fun"]
Explanation: The split()
method breaks the string into a list of words, separated by spaces in this case.