Python · The Python Data Model · Intermediate · 26 min read
Hashing, Equality and Immutability in Python: Safe Value Objects, Dict Keys and Frozen Data
Design objects that work correctly in sets and as dictionary keys. Learn identity versus equality, the hash/eq contract, how Python makes classes unhashable, building immutable value objects (frozen dataclasses, slots, __setattr__ guards, NamedTuple), caching hashes, MappingProxyType and frozenset, hashing pitfalls (mutable keys, NaN, float and int equality), and when immutability pays off.
Create an account to start
Create a free account to see what this lesson covers
- Every free lesson in every section, in full
- Track your progress and pick up where you left off
- Free practice questions and an incident simulation
- Takes under a minute: name, email and a password
No card needed. Full access to Python is a paid upgrade you can choose later.