Last Updated : 05 May, 2025
Our task is to Convert string to a list in Python. Whether we need to break a string into characters or words, there are multiple efficient methods to achieve this. In this article, we'll explore these conversion techniques with simple examples. The most common way to convert a string into a list is by using the split() method.
Using the split() MethodThe split() method by default splits a string based on spaces, but it can also split using a custom delimiter.
Python
s = "Geeks for Geeks"
a = s.split()
print(a)
['Geeks', 'for', 'Geeks']
Explanation: The split() method splits the string into words based on spaces.
Using list()If we want to break down a string into list of individual characters then we can use list() function which is a simple and effective method. This approach adds each character of the string as an element in a list.
Python
s = "Geeks for Geeks"
a = list(s)
print(a)
['G', 'e', 'e', 'k', 's', ' ', 'f', 'o', 'r', ' ', 'G', 'e', 'e', 'k', 's']
Explanation: The list(s) function takes every character in the string "s" and places it as an element in the list.
Using list comprehensionList comprehension can be used for converting a string into list of individual characters. This approach is particularly useful if we want to manipulate each character before adding it to the list. While a loop can also achieve the same result but list comprehension provides better readability and conciseness.
Python
s = "Geeks for Geeks"
a = [ch for ch in s]
print(a)
['G', 'e', 'e', 'k', 's', ' ', 'f', 'o', 'r', ' ', 'G', 'e', 'e', 'k', 's']
Explanation: [ch for ch in s] with this list comprehension we iterate over each character (ch) in the string "s" and add it to the list.
Related Articles:
Python | Program to convert String to a List
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4