Creating a List of Empty Lists
Fuzzyman
michael at foord.net
Fri Dec 5 07:19:30 EST 2003
"Francis Avila" <francisgavila at yahoo.com> wrote in message news:<vsvd2uq3mf7q5b at corp.supernews.com>...
> Fuzzyman wrote in message
> <8089854e.0312040649.4a7f1715 at posting.google.com>...
> >Pythons internal 'pointers' system is certainly causing me a few
> >headaches..... When I want to copy the contents of a variable I find
> >it impossible to know whether I've copied the contents *or* just
> >created a new pointer to the original value....
>
>
> You don't need to divine the rules for copy vs. reference: Python NEVER
> copies values, ONLY dereferences names, unless you EXPLICITLY ask for a copy
> (which Python-the-language doesn't have any special machinery for; you have
> to use the copy module or figure out how to copy the object yourself.)
>
[snip...] Interesting discussion reluctantly snipped.......
>
> The only mutable objects you usually have to worry about are dicts and
> lists.
Right - because if I do something like :
a = 4
b = a
a = 5
print b
It prints 4... not 5.
In other words - the line b = a creates a name pointing to the object
4, rather than a name pointing to the contents of a.....
I think I see what you mean - since the object 4 is immutable......
the line a = 5 destroys the old name a and creates a new one pointing
to object 5, rather than changing what the name a is pointing to.
Since lists and dictionaries are mutable..... changing the contents
modifies the object rather than destroying the refereence tothe old
one and creating a new one.....
Hmmmmmm... thanks.........
Fuzzy
More information about the Python-list
mailing list