hash() Hash of object
Last updated: 2026-09-22
hash() Hash of object
hash() returns the integer hash of a hashable object; a is b implies hash(a) == hash(b).
| Category | Built-in Functions |
|---|---|
| Kind | Built-in Function |
| Python Version | all |
📝 Syntax
hash(object)
⚙️ Parameters
| object Required | The object to hash; it must be hashable. |
|---|
Returns:The integer hash of the object; equal objects always hash equal.
💥 Raises
TypeError— Raised when the object is unhashable (e.g. list, dict, set).
▶ Example
Edit the code, press Run, and see the result in the output panel:
Output:
529344067295497451
ℹ️ Info Immutable containers are hashable; list / set / dict are not.
💡 Related Cases
More case studies coming soon — check back later.
❓ FAQ
QWhy does hash([1, 2]) raise a TypeError?
AA list is mutable — its contents can change — so its hash cannot be stable, hence it is unhashable. The same applies to dict and set.
QWhich objects are hashable?
AImmutable types are usually hashable: int, float, str, bytes, tuple, frozenset, None, etc. Note that a tuple containing a list is not hashable either.
QDo equal objects always have the same hash?
AAlways in one direction: if a == b then hash(a) == hash(b). But the reverse is not guaranteed — different objects may collide on the same hash (equal hash does not imply equality).
QDoes hash('abc') stay the same each time I run the program?
ANot necessarily. String hashing is randomized by default (PYTHONHASHSEED), so it is not stable across processes; do not use hash values for persistence or cross-process passing.