Explanation of list reference
roy at panix.com
Sat Feb 15 18:02:39 CET 2014
Steven D'Aprano <steve+comp.lang.python at pearwood.info>:
> > Object identity is simple and well-defined in Python. I don't know why
> > you are so resistant to this. Read the documentation.
Marko Rauhamaa <marko at pacujo.net>:
> It is not defined at all:
> Every object has an identity, a type and a value. An objectâs
> identity never changes once it has been created; you may think of it
> as the objectâs address in memory. The âisâ operator compares the
> identity of two objects; the id() function returns an integer
> representing its identity.
The "you may think of it as the object's address in memory" part is
misleading, and should be removed from the docs. While it's true that
you may think of it that way, such thinking just leads you to make
assumptions which are not universally true.
I agree with Marko that this is not a definition. It's a collection of
random statements about ids, their use, and some misleading philosophy.
Even the part about "... compares the identify of two objects" is kind
of funky, since it implies that you do indeed have two objects!
A definition would be:
"The identity of an object is an integer which never changes during the
lifetime of the object, and which is guaranteed to be distinct from the
identities of all other objects with overlapping lifetimes. A given
identity may be reused for objects with disjoint lifetimes".
That (I think) says everything is which is guaranteed about identities,
and nothing more. Once you've defined what an identity is, then you can
go on to describe some fun things you can do with it:
"The id() function returns the identity of an object. The 'is' operator
compares the identities of its two operands and returns True if they are
More information about the Python-list