En Sat, 07 Aug 2010 04:04:06 -0300, Stefan Schwarzer
<sschwar...@sschwarzer.net> escribió:
On 2010-08-07 00:28, Steven D'Aprano wrote:
Actually, yes, equality is implemented with a short-cut
that checks for
identity first. That makes something like:
[...]
Oops, I didn't realize that the OP had mentioned the
identity check as an optimization in case the objects are
the same. I thought he was confusing the operator with `is`.
s = "abc"*1000*1000*10
s == s
nice and quick, as Python can immediately recognise that a string is
always equal to itself without having to walk the entire string
comparing
each character with itself.
Yes, that definitely makes sense. I guess I would have
implemented it this way as well. :)
For strings and other internal types this optimization certainly makes
sense. For user-defined types it gets in the way and prevents defining an
object such x==x is False (like NANs).
--
Gabriel Genellina
--
http://mail.python.org/mailman/listinfo/python-list