Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Python by (16.4k points)

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:

    ...

1 Answer

0 votes
by (26.4k points)

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!

Related questions

0 votes
1 answer
asked Oct 5, 2019 in SQL by Tech4ever (20.3k points)
0 votes
1 answer
asked Sep 30, 2019 in Python by Sammy (47.6k points)
0 votes
1 answer
0 votes
1 answer
asked Feb 14, 2021 in Python by laddulakshana (16.4k points)

Browse Categories

...