Newbie question about reference

Alex Martelli aleax at aleax.it
Sun Mar 23 06:07:29 EST 2003


Tim Smith wrote:

> "Terry Reedy" <tjreedy at udel.edu> wrote:
>>You here bind 'list' to the object [1,2,3].  (Note: DON'T use builtin
>>names as vars unless you have a positive reason for so doing.)
> 
> OK, I had thought that L = [x,y,z] was binding the list L as an
> ordered set of references/pointers to the variables x, y, z. Obviously

Python has no such thing as a "reference to a variable".  References
always are to OBJECTS, i.e., VALUES.  Variables are just a kind of
reference to values, you could call them "plain-named references".

Don't think of variables as "boxes" having objects "inside", as you
might in some other languages; think of them as "post-it notes"
that may be temporarily "stuck onto" objects -- an object may at
any one time have one or several such references "stuck onto it".

Python is free to dispose of an object when the number of
references stuck onto the object falls to zero -- when and if it
will so dispose depends on other factors, e.g., as an implementation
detail, objects for small integers are always kept around, since
they're so often needed, rather than disposed and re-created each
time -- but this doesn't affect your application's code.


Alex





More information about the Python-list mailing list