Split String into List of Characters in Python

04-Nov-2022

.

Admin

Split String into List of Characters in Python

Hi Dev,

Here, I will show you how to works Split String into List of Characters in Python. Here you will learn Python String Split on Character Into List. This post will give you simple example of Python Split String Into List of Characters. We will look at example of How to Split a String in Python by Character. Here, Creating a basic example of How to Convert String to 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 following examples with output:

Example 1:


main.py

myString = "Site Nicesnippets.com"

# Convert String into List

newList = list(myString.strip(" "))

print(newList)

Output:

['S', 'i', 't', 'e', ' ', 'N', 'i', 'c', 'e', 's', 'n', 'i', 'p', 'p', 'e', 't', 's' , '.', 'c', 'o', 'm']

Example 2:

main.py

myString = "Nicesnippets.com is a best site!"

# Convert String into List

newList = myString.split(" ")

print(newList)

Output:

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

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']

#Python