AI engineering glossary · Python advanced

What is __eq__?

__eq__: The special method defining what == means for objects of a class. Without it, two objects are equal only if they are the very same object. Defining it usually calls for defining __hash__ too.

Level: intermediateTopic: Python advanced

__eq__: an example

def __eq__(self, o): return self.id == o.id treats two Customer objects with the same id as equal.

Related terms

More Python advanced terms

Where you learn it

__eq__ is part of the AI Engineering Program, which teaches it with notes, a hands-on lab and an exam. The first lesson is free.

Before you go

Take the cheat sheet with you

One free PDF: the key AI-engineering terms, formulas and Python idioms. No spam; unsubscribe any time.