<div dir="ltr">Sorry. I don't quite get it. As you said, it first tries, leftOperand.__eq__(rightOperand) then if it returns NotImplemented, it goes to invoke rightOperand.__eq__(leftOperand). But for any reason, [] == () returns false, why?</div>
<div class="gmail_extra"><br><br><div class="gmail_quote">On Mon, Aug 5, 2013 at 7:06 AM, Chris Angelico <span dir="ltr"><<a href="mailto:rosuav@gmail.com" target="_blank">rosuav@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class="im">On Sun, Aug 4, 2013 at 11:35 PM, Markus Rother <<a href="mailto:python@markusrother.de">python@markusrother.de</a>> wrote:<br>
> Hello,<br>
><br>
> The following behaviour seen in 3.2 seems very strange to me:<br>
><br>
> As expected:<br>
>>>> () == []<br>
> False<br>
><br>
> However:<br>
>>>> ().__eq__([])<br>
> NotImplemented<br>
>>>> [].__eq__(())<br>
> NotImplemented<br>
<br>
</div>You don't normally want to be calling dunder methods directly. The<br>
reasoning behind this behaviour goes back to a few things, including a<br>
way to handle "1 == Foo()" where Foo is a custom type that implements<br>
__eq__; obviously the integer 1 won't know whether it's equal to a Foo<br>
instance or not, so it has to defer to the second operand to get a<br>
result. This deferral is done by returning NotImplemented, which is an<br>
object, and so is true by default. I don't see any particular reason<br>
for it to be false, as you shouldn't normally be using it; it's more<br>
like a "null" state, it means "I don't know if we're equal or not". If<br>
neither side knows whether they're equal, then they're presumed to be<br>
unequal, but you can't determine that from a single call to __eq__.<br>
<br>
ChrisA<br>
<span class="HOEnZb"><font color="#888888">--<br>
<a href="http://mail.python.org/mailman/listinfo/python-list" target="_blank">http://mail.python.org/mailman/listinfo/python-list</a><br>
</font></span></blockquote></div><br><br clear="all"><div><br></div>-- <br><div dir="ltr"><div><a href="http://about.me/introom" target="_blank">http://about.me/introom</a><br></div><br></div>
</div>