On 2009-03-07 02:11, Albert Hopkins wrote:
On Sat, 2009-03-07 at 03:07 -0500, Albert Hopkins wrote:
On Fri, 2009-03-06 at 23:57 -0800, Paul Rubin wrote:
alex23<wuwe...@gmail.com>  writes:
But _you_ only _just_ stated "It does have some (generally small)
performance ramifications as
well" and provided timing examples to show it. Without qualification.
The performance difference can be large if the objects are (for
example) long lists.
I would think (not having looked) that the implementation of == would
first check for identity (for performance reasons)... but then that lead
me to ask: can an object be identical but not equal to itself?
... answered my own question


class Foo:
     def __eq__(self, b):
         return False

x == Foo()
x is x
-->  True

x == x
-->  False
And for a practical, real world example:

In [1]: inf = 1e200 * 1e200

In [2]: inf
Out[2]: inf

In [3]: nan = inf / inf

In [4]: nan
Out[4]: nan

In [5]: nan is nan
Out[5]: True

In [6]: nan == nan
Out[6]: False

--
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
 that is made terrible by our own mad attempt to interpret it as though it had
 an underlying truth."
  -- Umberto Eco

--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to