Splitting strings
Arne Martin Güettler
arneh++ at ifi.uio.no
Wed Oct 18 11:14:03 EDT 2000
Janne Sinkkonen wrote:
>
> joonas <keisari_ at hotmail.com> writes:
>
> > 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
>
> >>> a,b,c,d='1234'
That will of course give a, b, c and d as strings, if the intention was
to get them as integers, this will do the job:
a,b,c,d = map(int, '1234')
--
Arne Martin
More information about the Python-list
mailing list