python assignment

Erik Max Francis max at alcyone.com
Tue Jul 22 22:09:21 EDT 2003


dan wrote:

> What I need is an exact and unambiguous algorithm for determining when
> an assignment will change the id of the variable (or should I say,
> when the evaluation of an expression will cause a new object to be
> created).  Some of the issues involved can be discerned from the
> following session: ...

But this session only involves immutable objects (ints and floats). 
Since immutable objects can never change, whether two equal immutable
objects are identical is an implementation detail and cannot make a
difference in the real world.  The `is' tests you perform in your sample
code are exploring into the realm of transparent implementation-defined
behavior; it doesn't matter whether the objects end up being identical,
that's a matter of optimization.

Try performing analogous operations with _mutable_ objects like a list,
and see if you remain confused.

-- 
   Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/
 __ San Jose, CA, USA && 37 20 N 121 53 W && &tSftDotIotE
/  \ Many things are lost for want of asking.
\__/  (an English proverb)




More information about the Python-list mailing list