Hashes in Python

· todoroki's blog


I found out some interesting details about hashing in Python.

An object is hashable if it has __hash__(), that has hash value that never changes.

Immutable data, or even mutable data that is guaranteed to no change, has hash available.

Hashable types: #

These are commonly hashable in Python, int, float, complex, str, bytes, bytearray, tuples (if elements are hashable), frozenset (immutable, so data is constant, therefore hashable), or any object that has __hash__ and __eq__.

Non hashable types: #

list, dict, set because their data can change (behind a pointer), most mutable objects.