AI engineering glossary · Python advanced

What is __hash__?

__hash__: The special method returning an integer used to place an object in sets and as a dictionary key. Objects that compare equal must have equal hashes, and mutable objects are usually left unhashable.

Level: advancedTopic: Python advanced

__hash__: an example

def __hash__(self): return hash(self.id) lets Customer objects be stored in a set by their id.

Related terms

More Python advanced terms

Where you learn it

__hash__ 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.