"/a" is not "/a" ?

Steven D'Aprano steve at pearwood.info
Sat Mar 7 09:19:38 CET 2009

Albert Hopkins wrote:

> I would think (not having looked) that the implementation of == would
> first check for identity (for performance reasons)...

For some types, it may. I believe that string equality testing first tests
whether the two strings are the same string, then tests if they have the
same hash, and only then do a character-by-character comparison. Or so I've
been told.

> can an object be identical but not equal to itself?

Yes. Floating point NANs are required to compare unequal to all floats,
including themselves. It's part of the IEEE standard.

Python doesn't assume that == must mean equality. If, for some bizarre
reason you want to define == to mean something completely different, then
you can define x == x to return anything you like for your class.


More information about the Python-list mailing list