Creating a List of Empty Lists

Francis Avila francisgavila at yahoo.com
Fri Dec 5 17:26:40 EST 2003


Fuzzyman wrote in message
<8089854e.0312050419.2cf36e34 at posting.google.com>...
>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.....


Correct, but it's not so much the contents of 'a', but the thing that 'a'
points to.  Thinking of names as having a "contents" is bound to lead to
confusion later.  In any case, as far as 'b' is concerned, there's nothing
in the universe besides itself and the object it points to.  It doesn't know
anything about the existence of 'a'.  Python sees what object the right side
of the assignment operator points to, and then tells the names on the left
side, "Hey, you! Point to this object!"

Names are not objects, and names point only to objects, not to names.  This
doesn't mean that names aren't *things*: they certainly are, because objects
can contain names.

This is more natural than you might think, because you do it in language.
When you say "chair", the sound points to the concept "chair".  The sound
isn't a chair, nor does it contain a chair, but when someone else hears the
sound, it evokes the same "chair" concept, and not the sound itself.
However, the name is still a *thing* (you can speak it, put it in a book,
etc.), even though its existence is transparent.

>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.


It doesn't create or destroy the old name: it just makes it point to
something else.  Names are created by '=' if the name didn't exist before,
and destroyed by 'del' or by going out of scope.

>Hmmmmmm... thanks.........


No problem.  I think you've got the hang of things.


--
Francis Avila





More information about the Python-list mailing list