0
0
PythonHow-ToBeginner · 3 min read

How to Split String into List of Characters in Python

To split a string into a list of characters in Python, use the list() function with the string as its argument. This converts each character in the string into an individual element in the list.
📐

Syntax

The syntax to split a string into a list of characters is simple:

  • list(string): Converts the string into a list where each character is an element.
python
list_of_chars = list("hello")
💻

Example

This example shows how to split the string "hello" into a list of characters.

python
word = "hello"
chars = list(word)
print(chars)
Output
['h', 'e', 'l', 'l', 'o']
⚠️

Common Pitfalls

A common mistake is trying to use split() without arguments, which splits by spaces, not characters. Also, using a loop to append characters manually is less efficient.

python
word = "hello"
# Wrong: split() splits by spaces, not characters
chars_wrong = word.split()
print(chars_wrong)  # Output: ['hello']

# Right: use list() to get characters
chars_right = list(word)
print(chars_right)  # Output: ['h', 'e', 'l', 'l', 'o']
Output
['hello'] ['h', 'e', 'l', 'l', 'o']
📊

Quick Reference

Use list(string) to get a list of characters from any string quickly and easily.

MethodDescriptionExample
list(string)Converts string to list of characterslist("abc") → ['a', 'b', 'c']
string.split()Splits string by spaces (not characters)"a b c".split() → ['a', 'b', 'c']

Key Takeaways

Use list(string) to split a string into characters easily.
Do not use split() without arguments to get characters; it splits by spaces.
list() returns each character as a separate list element.
This method works for any string, including empty strings.
Avoid manual loops for splitting characters unless needed for special cases.