list vs tuple

deadmeat root at [127.0.0.1]
Sun Apr 1 03:42:20 EDT 2001


> a = [1, 2, 3]
> b = a
> b = [4, 5, 6]
> a is still [1, 2, 3]. What's the problem?

[4,5,6] is a new object. b = a still didn't duplicate a, as would have been
expected. the first thing a newbie will do is play with simple integer
values. a = 1;b = a; a = 2; leaves you with a and b of different values. So
it appears b = a copies the value from b to a because changing a does not
affect b. the truth is not realised until later..









More information about the Python-list mailing list