Python Split String into List of Characters Example

By Hardik Savani October 30, 2023 Category : Python

Today our leading topic is python convert string to list of characters. This post will give you simple example of how to convert string to list in python. I explained simply step by step how to split a string in python by character. you can understand a concept of python split string into list of characters.

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.

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

let's see below a simple example with output:

Example 1:

myString = "Site"
# Convert String into List
newList = list(myString.strip(" "))


['S', 'i', 't', 'e', ' ', 'I', 't', 'S', 'o', 'l', 'u', 't', 'i', 'o', 'n', 'S', 't', 'u', 'f', 'f', '.', 'c', 'o', 'm']

Example 2:

myString = " is a best site!"
# Convert String into List
newList = myString.split(" ")


['', 'is', 'a', 'best', 'site!']

Example 3:

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


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

I hope it can help you...

Tags :