String help

Steve Holden sholden at holdenweb.com
Mon Oct 7 16:30:08 CEST 2002


"CheapSkate" <gua81 at XXXyahoo.com> wrote ...
> and that will give me??
> aaa, bbb or ccc?
>
[Pádraig's suggestion
]

As with many suggestions you will receive in response to comp.lang.python
questions, the easiest thing is to try running them in an interactive
interpreter session, as follows...

>>> "aaa,bbb,ccc".split(",")
['aaa', 'bbb', 'ccc']
>>>

As you can see, the split() function returns a list comprising the
substrings around the separator (which was a comma in this case).

If you want a particular substring you should subscript the resulting list,
e.g.:

>>> r = "aaa,bbb,ccc".split(",")
>>> r[1]
'bbb'
>>>

Hope this helps.

regards
-----------------------------------------------------------------------
Steve Holden                                  http://www.holdenweb.com/
Python Web Programming                 http://pydish.holdenweb.com/pwp/
Previous .sig file retired to                    www.homeforoldsigs.com
-----------------------------------------------------------------------






More information about the Python-list mailing list