Python | Split string into list of characters
View Discussion
Improve Article
Save Article
Like Article
- Difficulty Level : Basic
- Last Updated : 19 Feb, 2021
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 List Comprehension
This approach uses list comprehension to convert each character into a list. Using the following syntax you can split the characters of a string into a list.
Python3
# Python3 program to Split string into charactersdef split(word): return [char for char in word] # Driver codeword = 'geeks'print(split(word)) |
Output:
['g', 'e', 'e', 'k', 's']
Code #2 : Typecasting to list
Python provides direct typecasting of string into list using list().
Python3
# Python3 program to Split string into charactersdef split(word): return list(word) # Driver codeword = 'geeks'print(split(word)) |
Output:
['g', 'e', 'e', 'k', 's']
My Personal Notes
arrow_drop_up
Recommended Articles
Page :
Article Contributed By :
Improved By :
Practice Tags :


