Is there a magic method in python for the "in" method? For example,
y = [5, 4, 3, 2,1]
5 in y #returns true
if so what is it, and if not, how would one implement it.
Is there a magic method in python for the "in" method? For example,
y = [5, 4, 3, 2,1]
5 in y #returns true
if so what is it, and if not, how would one implement it.
It's __contains__()
:
>>> y = [5, 4, 3, 2, 1]
>>> y.__contains__(3)
True
>>> y.__contains__(6)
False