Python Convert String into List of Words Example

Published on Jul 26, 2022

Hi Dev,

There are several ways to convert strings into a list in python. we will use split() and strip() functions to convert string into list. so let's see the below examples.

You can use these examples with python3 (Python 3) version.

let's see below a simple example with output:

Example 1

main.py
myString = "ItSolutionStuff.com is a best site!"
  
# Convert String into List
newList = myString.split(" ")
    
print(newList)

Output:

['ItSolutionStuff.com', 'is', 'a', 'best', 'site!']

Example 2

main.py
myString = "One,Two,Three,Four,Five"
  
# Convert String into List
newList = myString.split(",")
  
print(newList)

Output:

['One', 'Two', 'Three', 'Four', 'Five']

I hope it can help you.