list vs tuple
Chris Tavares
ctavares at develop.com
Sat Mar 31 16:17:13 EST 2001
"deadmeat" <root@[127.0.0.1]> wrote in message
news:uGqx6.1052$p5.3997 at news1.rivrw1.nsw.optushome.com.au...
> > - There is an difference between "copy" and "deep copy". What happens if
> > you make copy a structure that contains pointers in it?
>
> then you got a problem :)
>
> but thats not the point - which when the statement a = b copies the data
> across for one type it's expected to do it for others. It doesn't, so
it's
> inconsistant, contrary to the original claim.
>
Here's the root of your problem. a = b does NOT, I repeat, does NOT do any
data copying!!!!!
When you do this:
a = 5
You've now got a name, a, that points to an integer object out on the heap.
Similarly, when you do:
b = 9
b now points to an integer object out on the heap. And then, when you do:
a = b
a and b now point to the same integer object 9, and the integer 5 gets
garbage collected at some unknown point in the future.
So, when you do this with lists:
a = [ 1, 2, 3 ] <--- we'll call this list1. It lives on the heap.
b = a <- b now also points to list1.
b[1] = 5 <- This is a method call on the thing b points to, which of
course is the same thing as what a points to!
>>> a
[ 5, 2, 3]
Did this help?
-Chris
More information about the Python-list
mailing list