addressof object with id()

Roy Smith roy at
Sun Mar 24 02:20:05 CET 2013

In article <mailman.3659.1364086613.2939.python-list at>,
 Chris Angelico <rosuav at> wrote:

> On Sun, Mar 24, 2013 at 11:49 AM, Dave Angel <davea at> wrote:
> > You can assume that if the id's are equal, the objects are equal.  But you
> > can't assume the inverse or the converse.
> To be more specific: If the ids are equal, the objects are identical.
> Doesn't mean they'll compare equal - for instance, float("nan") isn't
> equal to itself. But for most situations, you can assume that
> identical objects compare equal.

>>> n = float("nan")

# No real surprise here
>>> n == n

# But this is kind of weird
>>> [n] == [n]

In fact, that's actually a bug (or at least, contrary to the documented 
behavior).  The docs ( 

> In particular, tuples and lists are compared lexicographically by comparing 
> corresponding elements. This means that to compare equal, every element must 
> compare equal and the two sequences must be of the same type and have the 
> same length

and that's not what's happening here:

>>> l1 = [n]
>>> l2 = [n]
>>> l1 == l2
>>> l1[0] == l2[0]

More information about the Python-list mailing list