Hashable
A hashable object has a stable hash value and compatible equality behavior, allowing it to be used as a dictionary key or set element.
Python How-To
A hashable object is a Python object with a stable hash value and equality behavior that allow it to serve as a dictionary key or set element.
- How it is used
- Guides the choice of objects used as dictionary keys and set elements.
- How deep it goes
- Explains hash consistency, collisions, mutability, common types, and runtime checks, but does not detail hash-table implementation protocols.
- Examples
- Uses failed dictionary and set constructions, hash calls, and a Hashable-based type-checking script.
- What you can do after
- Diagnose TypeError failures and select suitable dictionary keys or set elements using Hashable checks.
Python Workout: 50 ten-minute exercises
A hashable type has values with stable hash values and can therefore be used for dictionary keys or set elements.
- How it is used
- Explains why dictionary keys must be hashable and how that requirement supports unique, efficient lookup.
- How deep it goes
- Defines hashability through hash(), contrasts O(n) sequence search with O(1) dictionary lookup, and only raises collision handling.
- Examples
- Uses an office-directory analogy and contrasts strings, lists, and tuples with dictionary lookup.
- What you can do after
- Understand which values can serve as dictionary keys and why hashing makes lookup efficient.
Read how Python Workout: 50 ten-minute exercises explains hashable →
Python Workout, Second Edition
A hashable object is a Python object with a stable hash value that can be used as a dictionary key.
- How it is used
- Uses hashability to determine which Python objects can act as dictionary keys and support efficient lookup.
- How deep it goes
- Explains hash functions through lookup behavior and complexity, but stops short of implementation details.
- Examples
- Uses numbers and strings as keys and contrasts unrestricted dictionary values with unique keys.
- What you can do after
- Apply it by selecting hashable objects for dictionary keys while storing arbitrary values.
Also covered in
- The Quick Python Book, Fourth Edition
- Tiny Python Projects: Learn coding and testing with puzzles and games
What to know first
- MapA map is an associative data structure that stores key-value associations and supports retrieving values by key.
- loopA loop is a programming-language control-flow construct that repeatedly executes a block of instructions according to an iteration rule or continuation condition.
- tupleA tuple is a finite, ordered collection of values grouped as a single composite value, often with elements of different types.
Related concepts
- Mapused by · A map is an associative data structure that stores key-value associations and supports retrieving values by key.
- unhashablecontrasts with · In Python, unhashable describes an object that cannot be used as a dictionary key or set element because it lacks a suitable stable hash value.
- statecontrasts with · State is information describing the condition or configuration of a system or computation at a particular time that may influence its behavior or subsequent transitions.
- immutable collectionequivalent to · An immutable collection is a collection whose contents cannot be changed after it is created.
- similarity searchproduces · Similarity search is a retrieval technique that finds or ranks items by comparing their representations with a query representation under a similarity or distance measure.
Questions about hashable
What is hashable?
A hashable object has a stable hash value and compatible equality behavior, allowing it to be used as a dictionary key or set element.
Which Manning books explain hashable?
Python How-To, Python Workout: 50 ten-minute exercises and Python Workout, Second Edition.
What should I know before learning hashable?
Manning books that teach hashable usually introduce Map, loop and tuple first.
What is the difference between hashable and unhashable?
A hashable object has a stable hash value and compatible equality behavior, allowing it to be used as a dictionary key or set element. In Python, unhashable describes an object that cannot be used as a dictionary key or set element because it lacks a suitable stable hash value.
These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.


