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