Python Convert String into List Example

Published On: 16/11/2022 | Category: Python


Hi Guys,

This simple article demonstrates of Python Convert String into List Example. step by step explain how to convert string into list in python. I explained simply step by step how to turn string into list in python. you'll learn python string into list. follow bellow step for how to convert string into list of words in python.

Python has numerous methods for converting strings into lists. To transform a string into a list, we will utilise the split() and strip() functions. So let's look at the examples below.

So let's see bellow example:

Example 1:

main.py
myString = "Tuts-Station.com is a best site!"
  
# Convert String into List
newList = myString.split(" ")
    
print(newList)
Output
['Tuts-Station.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']

It will help you....

Happy Pythonic Coding!