I was not able to find anything useful in the documentation for Python 3.6. However, the docs for 3.10 state:
By default,
object
implements__eq__()
by usingis
, returningNotImplemented
in the case of a false comparison:True if x is y else NotImplemented
.
This seems to be right for Python 3.6 as well.
class Foo():
pass
print(Foo().__eq__(Foo())) # prints NotImplemented
However, I don't understand why
print(Foo() == Foo()) # prints False
prints not NotImplemented
, but False
. What is ==
doing here?