Convert a String to List of Character
Given a string
myStr, we have to convert the string
myStr to a list, where the elements of the list are the characters in the string, in respective order.
To convert the given string into a list of characters in Python, use List Comprehension with the given string as iterable. Since the string is an iterable of characters, the list comprehension with the string returns an list of characters.
The syntax of the expression to convert a string
myStr into a list of characters using List Comprehension is
In the following program, we take a string
myStr and convert this string into a list of characters.
Run Code Online
myStr = 'apple' arr = [*myStr] print(arr)
['a', 'p', 'p', 'l', 'e']
In this tutorial of Python Examples, we learned how to convert a string to a list of characters using List Comprehension, with the help of well detailed examples.