addressof object with id()

Steven D'Aprano steve+comp.lang.python at
Sun Mar 24 03:04:15 CET 2013

On Sun, 24 Mar 2013 11:56:50 +1100, Chris Angelico 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.

Also note that containers are permitted to assume reflexivity, that is, 
that x == x. That sometimes means that they don't play well with non-
reflexive values such as NANs.

e.g. x = [float('nan')]
x == x even though x[0] != x[0]

This has been discussed repeatedly on the Python-Dev mailing list, and 
the consensus is that there is no real consensus. Those who don't do 
serious floating point work hate NANs, those who do are split between 
loving NANs and merely tolerating them because the IEEE standard requires 
them, but pretty much everyone agrees that containers should be free to 
assume identity implies equality.


More information about the Python-list mailing list