Python Programming - Tricky Questions - Discussion

Discussion Forum : Tricky Questions - General Questions (Q.No. 18)
18.
Consider the following Python code:
class CustomClass:
    def __init__(self, value):
        self.value = value

    def __eq__(self, other):
        return self.value == other.value

obj1 = CustomClass(10)
obj2 = CustomClass(10)
result = obj1 == obj2
print(result)
What will be the value of result?
True
False
This code will result in an error.
This code will result in an infinite loop.
Answer: Option
Explanation:
The custom __eq__ method is defined to compare the value attribute of the objects.
Discussion:
Be the first person to comment on this question !

Post your comments here:

Your comments will be displayed after verification.