__hash__

The dunder method that returns an object's hash value, which lets it be a dictionary key or a set member.

In more detail

It must be consistent with __eq__: equal objects need equal hashes, and the hash must not change while the object is in a set or dictionary, so hash only fields that never change. Dataclasses can generate a matching pair for you with frozen=True.

Related terms

Taught in

References