Operators in
and not in
, also called "membership test operators", require that the right operand
supports the membership protocol.
In order to support the membership protocol, a user-defined class should implement at least one of the following methods:
__contains__
, __iter__
, __getitem__
.
If none of these methods is implemented, a TypeError
will be raised when performing a membership test.