Python | Split string into list of characters
Given a string, write a Python program to split the characters of the given string into a list.
Examples:
Input : geeks Output : ['g', 'e', 'e', 'k', 's'] Input : Word Output : ['W', 'o', 'r', 'd']
Code #1 : Using For loop
This approach uses for loop to convert each character into a list. Just enclosing the For loop within square brackets [] will split the characters of word into list.
# Python3 program to Split string into characters def split(word): return [char for char in word] # Driver code word = 'geeks'print(split(word)) |
['g', 'e', 'e', 'k', 's']
Code #2 : Typecasting to list
Python provides direct typecasting of string into list using list().
# Python3 program to Split string into characters def split(word): return list(word) # Driver code word = 'geeks'print(split(word)) |
['g', 'e', 'e', 'k', 's']
Recommended Posts:
- Python | Split string in groups of n consecutive characters
- Python | Pandas Split strings into two List/Columns using str.split()
- Python | Convert a list of characters into a string
- Python | Splitting string to list of characters
- Python | Splitting string to list of characters
- Python | Ways to split strings on Uppercase characters
- Python | Convert list of strings and characters to list of characters
- Python | Split list into lists by particular value
- Python | Custom list split
- Python | Split nested list into two lists
- Python | Split a list into sublists of given lengths
- Python | Split a list having single integer
- Python | Split dictionary of lists to list of dictionaries
- Python | Split strings in list with same prefix in all elements
- Python | Split given list and insert in excel file
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



