If I am creating my own class in Python, what function should I define so as to allow the use of the in
operator, e.g.
class MyClass(object):
...
m = MyClass()
if 54 in m:
...
See also What does __contains__ do, what can call __contains__ function for the corresponding question about what __contains__
does.
is
andis not
operators. Like aquery = tinydb.Query().field == value
, to also be able to writeQuery().field is not None
. But it seems I'm left with__eq__
and__ne__
for the time being, which leads to the unpythonicQuery().field != None
. (sarc) – Tamikatamiko