A

Admin • 828.03K Points
Coach

Q. What is output of the following code?

Code:
class A:
def __init__(self, x):
self.x = x
def __eq__(self, other):
return self.x == other.x

a = A(5)
b = A(5)
print(a == b)
  • (A) True
  • (B) False
  • (C) Error
  • (D) None
  • Correct Answer - Option(A)
  • Views: 5
  • Filed under category Python
  • Hashtags:

Explanation by: Admin
`__eq__` method compares the values of `x` in both objects, so returns True.

You must be Logged in to update hint/solution

Discusssion

Login to discuss.

Be the first to start discuss.