Where's the documentation to support the following behavior...

Josh Holland jrh at joshh.co.uk
Tue Mar 17 23:24:11 CET 2009


On Tue, Mar 17, 2009 at 03:14:39PM -0700, grocery_stocker wrote:
> It seems like id(list[<some value>]) == id(<some value>).

Only when certain immutable objects are involved. It is the
implementation's option to allow different immutable values to be the
same object (same id()). In CPython, this is used to cache strings that
look like identifiers and small integers. This has been discussed here 
a lot; have a look at the archives.

-- 
Josh Holland <jrh at joshh.co.uk>
http://joshh.co.uk
madmartian on irc.freenode.net



More information about the Python-list mailing list