splitting strings into variables
Scott David Daniels
scott.daniels at acm.org
Mon Apr 14 21:36:28 EDT 2003
lost wrote:
>...
> strname.split(":")
> print strname
> hello
You are close. Strings are values, not variables, so you
don't modify strname directly. Try:
strname = "hello:there"
first,last = strname.split(":")
print first
Of course, this is often better as:
first,last = strname.split(":", 1)
if you know there is a colon, or as:
first = strname.split(":")[0]
-Scott David Daniels
More information about the Python-list
mailing list