Override Python's 'in' operator?

astrofrog picture astrofrog · Feb 7, 2010 · Viewed 70.6k times · Source

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:
    ...