how to split a string in python

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

Answer is: You need Lists.

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

Docs: http://docs.python.org/library/functions.html#list

You take the string and pass it to list()

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

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

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

If you want to process your String one character at a time. you have various options.

#See for more examples:
https://stackoverflow.com/questions/4978787/how-to-split-a-string-into-a-list-of-characters-in-python

also asked:

how to split a string in python

how to split a string into a list of characters in python

how to split up a string in python

Leave a comment