How to Split a String into Characters in Python?

In this tutorial, I will explain how to split a string into characters in Python. Recently in a Python webinar, someone asked me a question on how to split a string into characters. After exploring many various methods I found some effective ways to accomplish this which I will explain in this article. Let us learn more about this topic with suitable examples.

Split a String into Characters in Python

Let us see some important methods to split strings into characters in Python.

Read How to Insert a Python Variable into a String?

Method 1. Use the List() Function

One of the simplest ways to split a string into characters is by using the built-in list() function in Python. This function takes a string as input and returns a list of individual characters. Here’s an example:

name = "John Doe"
character_list = list(name)
print(character_list)

Output:

['J', 'o', 'h', 'n', ' ', 'D', 'o', 'e']

I have executed the above example code and added the screenshot below.

Split a String into Characters in Python

In this example, we have a string "John Doe" representing a person’s name. By passing the string to the list() function, we obtain a list of individual characters, including the space character.

Check out How to Split a String by Index in Python?

Method 2. Use List Comprehension

Another concise way to split a string into characters is by using list comprehension in Python. List comprehension allows us to create a new list based on an existing iterable, such as a string. Here’s an example:

name = "Emily Johnson"
character_list = [char for char in name]
print(character_list)

Output:

['E', 'm', 'i', 'l', 'y', ' ', 'J', 'o', 'h', 'n', 's', 'o', 'n']

I have executed the above example code and added the screenshot below.

How to Split a String into Characters in Python

In this approach, we use a list comprehension to iterate over each character in the string "Emily Johnson" and create a new list containing those characters.

Read Convert Binary to Decimal in Python

Method 3. Use the Unpacking Operator (*)

Python’s unpacking operator * can also be used to split a string into a list of characters. This approach is compact and works well for most scenarios. Here’s an example:

name = "Michael Smith"
character_list = [*name]
print(character_list)

Output:

['M', 'i', 'c', 'h', 'a', 'e', 'l', ' ', 'S', 'm', 'i', 't', 'h']

I have executed the above example code and added the screenshot below.

Split a String into Characters in Python unpacking operator

By prefixing the string "Michael Smith" with the unpacking operator * , we can directly convert it into a list of characters.

Check out How to Split a String Every N Characters in Python?

Method 4. Use Slicing

In Python, strings are already arrays of characters for all purposes except replacement. We can use slicing to split a string into individual characters. Here’s an example:

name = "Olivia Brown"
character_list = [name[i] for i in range(len(name))]
print(character_list)

Output:

['O', 'l', 'i', 'v', 'i', 'a', ' ', 'B', 'r', 'o', 'w', 'n']

In this approach, we use list comprehension along with slicing. We iterate over the indices of the string “Olivia Brown” range(len(name)) and access each character using name[i]. This creates a new list containing the individual characters.

Read Python Split Regex

Conclusion

In this tutorial, we explored different methods to split a string into characters in Python. Whether you prefer using the list() function, list comprehension, the unpacking operator, or slicing, Python provides multiple ways to achieve this task efficiently.

You may also like to read:

51 Python Programs

51 PYTHON PROGRAMS PDF FREE

Download a FREE PDF (112 Pages) Containing 51 Useful Python Programs.

pyython developer roadmap

Aspiring to be a Python developer?

Download a FREE PDF on how to become a Python developer.

Let’s be friends

Be the first to know about sales and special discounts.