[Tutor] Sequential assignment to list subscripts

John Abbe johnca@ourpla.net
Sun Nov 3 01:57:01 2002


Found my own answer:

At 10:41 PM -0800 on 2002-11-02, John Abbe typed:
>Sequential assignment to integer variables works:
>
>>>>  a, b=5, 6
>>>>  a
>5
>>>>  b
>6
>
>Great. Can someone explain...
>
>>>>  a=b=[0]

Oops. That set a and b to refer to the same list in memory...

>>>>  a
>[0]
>>>>  b
>[0]
>>>>  a[0], b[0] = 7, 8

...so a[0] = 7 sets that one list to [7], then b[0] = 8 sets it to [8].

>>>>  a
>[8]
>>>>  b
>[8]
>
>...why a[0] isn't equal to 7  ?!?

Because it refers to the same list that b[0] does.

I'll get that referencing eventually. Is there a handy way set a 
bunch of variables to *copies* of the same thing?

Life,
John
-- 
  All you  /\/\ John Abbe             "If you don't like the news,
      need \  / CatHerder              go out and make some of your own."
      is... \/  http://www.ourpla.net/john/               --Wes Nisker