Python · Classes and objects

__eq__

Defines equality. Return NotImplemented for unrelated types so Python can try the other side.

Syntax
def __eq__(self, other):

Example

Open in the lab

More in this group

__init__ __repr__ @classmethod @dataclass @property @staticmethod class Dunder methods

Learn this in the course

Reference pages are the quick answer. The course explains the why, shows the full example and ends with a challenge.

Open the course