Python Programming - Polymorphism - Discussion

Discussion Forum : Polymorphism - General Questions (Q.No. 49)
49.
In Python, what is the purpose of the __contains__() method?
To define class attributes
To customize the behavior when an item is checked for membership using the in keyword
To create a new instance of the class
To customize the behavior when an instance is compared using the == operator
Answer: Option
Explanation:
The __contains__() method is used to customize the behavior when an item is checked for membership using the in keyword, allowing for polymorphic behavior.
Discussion:
Be the first person to comment on this question !

Post your comments here:

Your comments will be displayed after verification.