How to Split String into List of Characters in Python?

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


Hi Guys,

This tutorial shows you how to convert string to list in python. let’s discuss about how to split a string in python by character. I would like to share with you python split string into list of characters. I explained simply step by step python convert string to list of characters. follow bellow step for python string split on character into list.

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

So let's see bellow example:

Example 1:

main.py
myString = "Hello World"
  
# Convert String into List
newList = list(myString.strip(" "))
  
print(newList)
Output
['H', 'e', 'l', 'l', 'o', ' ', 'W', 'o', 'r', 'l', 'd']

Example 2:

main.py
myString = "Hello World"
  
# Convert String into List
newList = myString.split(" ")
    
print(newList)
Output
['H', 'e', 'l', 'l', 'o', ' ', 'W', 'o', 'r', 'l', 'd']

Example 3:

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!