[Tutor] Sequential assignment to list subscripts

Sean 'Shaleh' Perry shalehperry@attbi.com
Sun Nov 3 01:55:02 2002


On Saturday 02 November 2002 22:41, John Abbe wrote:
> Great. Can someone explain...
>
> >>>  a=3Db=3D[0]
> >>>  a
>
> [0]
>
> >>>  b
>
> [0]
>
> >>>  a[0], b[0] =3D 7, 8
> >>>  a
>
> [8]
>
> >>>  b
>
> [8]
>
> ...why a[0] isn't equal to 7  ?!?
>
> (and more to the point, what the proper syntax would be?)
>

Your problem comes from how you defined a and b.

What you really said was a =3D (b =3D [0]) which means 'a' gets assigned =
a=20
reference to 'b' and thus changing one changes the other.  This works tho=
ugh:

>>> a =3D [0]
>>> b =3D [0]
>>> a[0], b[0] =3D 7, 8
>>> print a
[7]
>>> print b
[8]