How to split a string into a list of characters in Python? How to split a string into a list of characters in Python? python python

How to split a string into a list of characters in Python?


>>> s = "foobar">>> list(s)['f', 'o', 'o', 'b', 'a', 'r']

You need list


You take the string and pass it to list()

s = "mystring"l = list(s)print l


You can also do it in this very simple way without list():

>>> [c for c in "foobar"]['f', 'o', 'o', 'b', 'a', 'r']