Variable Scope 2 -- Thanks for 1.
Jens Thiede
jensthiede at webgear.co.za
Fri Jan 9 15:47:13 EST 2004
I found the querk in my code:
a = [1, 2, 3];
b = a;
b.append(4);
b == [1, 2, 3, 4]; # As it should.
a == [1, 2, 3, 4]; # - Why?
One would think that b is a referance to a - however I know it's not.
Without changing a thing from above, the following is true:
b = [];
b.append(5);
a == [1, 2, 3, 4];
b == [5];
How do I avoid accedentaly modifying variables, is this a bug? If not
why not?
Jens Thiede.
By the way, living in South Africa, where we have 11 national
languages is nice although - as a result - the World does not know
what to think of us. :)
More information about the Python-list
mailing list