How does the in
operator work for Python?
In the example below I have two namedtuples that are different objects, but the in
operator evaluates to True for an array containing one of the objects.
Is in
checking if the array contains the object, or does it check if any object in the array is equivalent? I tried searching for documentation but couldn't find anything specific, just simple examples.
In [3]: a = namedtuple('test', ['t']) In [6]: b = a(1) In [7]: c = a(1) In [8]: b is c
Out[8]: False In [9]: id(b)
Out[9]: 54740808 In [10]: id(c)
Out[10]: 88817352 In [11]: c in [b]
Out[11]: True In [12]: b in [c]
Out[12]: True In [13]: c == b
Out[13]: True