Consider the following code:
>>> class A(object):
... def __init__(self, a):
... self.a = a
... def __eq__(self, other):
... return self.a==other.a
...
>>> a=A(1)
>>> b=A(1)
>>> c=A(2)
>>> a==b
True # because __eq__ says so
>>> a==c
False # because __eq__ says so
>>> a is b
False # because they're different objects
>>> l = [b,c]
>>> a in l
True # seems to use __eq__ under the hood
So, in
seems to use __eq__
to determine whether or not something is in a container.
- Where can one find documentation on this behavior?
- Is it possible to make
in
use object identity, a.k.a.a in somelist
if the objecta
is insomelist
, and not some other object that compares equal toa
?