Splitting strings

Wolfgang Grafen Wolfgang.Grafen at marconi.com
Wed Oct 18 11:03:04 EDT 2000


joonas wrote:
> 
> i have a string "8643" how can i split it into variables:
> firstvar, secondvar, thirdvar and fourthvar.
> 
> Then variables would contain:
> 
> firstvar = 8
> secondvar = 6
> thirdvar = 4
> fourthvar = 3
> 
> 
Try this:

>>> firstvar,secondvar,thirdvar,fourthvar = map(None,"8643")
>>>
>>> print """\     
... firstvar = %s
... secondvar = %s
... thirdvar = %s
... fourthvar = %s
... """%(firstvar,secondvar,thirdvar,fourthvar)
firstvar = 8
secondvar = 6
thirdvar = 4
fourthvar = 3

regards

Wolfgang



More information about the Python-list mailing list