in-operator

Override Python's 'in' operator?

Override Python's 'in' operator? Question: 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: … Asked By: astrofrog || Source Answers: MyClass.__contains__(self, item) Answered By: Ignacio Vazquez-Abrams A more …

Total answers: 3