Back
Let's assume, I am making my own class in Python, what function should I define in order to permit the utilization of the 'in' operator, for example
class MyClass(object): ...m = MyClass()if 54 in m: ...
class MyClass(object):
...
m = MyClass()
if 54 in m:
Try the following code:
MyClass.__contains__(self, item)
This function helps you to define in order to permit the use of the 'in' operator.
Are you interested to learn more concepts related to python? Join python certification course fast!
31k questions
32.8k answers
501 comments
693 users