how do i change from string to list

Steve lonetwin at gmail.com
Mon Oct 25 04:19:01 EDT 2004


Hi John,
     Although you already have the reply to your question, I thought I
should point one thing out. I have seen plenty of newbies wanting to
convert a string to a list so that they can do some sort of list
related manipulation on it. The good thing about python strings though
is, they are valid "sequences", which means that any sequence related
operations can also be carried out on strings.

For example:
>>> s = "foobar"
>>> for i in s:
...     print i, 
... 
f o o b a r
>>> s[3:]
'bar'
>>> s[:-1]
'fooba'
>>>

...but I guess you already knew that :)

HTH someone,
Regards
Steve



More information about the Python-list mailing list