The hash value of an object is an integer returned by its __hash__
method. Objects that are considered equal to each other (as per the
__eq__
method) should have the same hash value.
Whenever using an object as a dictionary key or inserting it into a set, the hash value of that object will be used to derive a bucket in which the
object will be inserted.
When attempting to insert an unhashable object into a set, a TypeError
will be raised instead.
If an object defines a __hash__
method derived from mutable properties, no TypeError
will be raised. However, having a
mutable hash value should never be done as this would prevent dictionaries and set from retrieving the object.