Immutable means that object will not change in any significant manner during its lifetime. It's a vague but common idea in programming languages.
Hashability is slightly different, and refers to comparison.
hashable An object is hashable if it has a hash value which never
changes during its lifetime (it needs a __hash__()
method), and can be
compared to other objects (it needs an __eq__()
or __cmp__()
method).
Hashable objects which compare equal must have the same hash value.
All user-defined classes have __hash__
method, which by default just returns the object ID. So an object that meets the criteria for hashability is not necessarily immutable.
Objects of any new class you declare can be used as a dictionary key, unless you prevent it by, for example, throwing from __hash__
We could say that all immutable objects are hashable, because if the hash changes during the object's lifetime, then it means that the object mutated.
But not quite. Consider a tuple which has a list (mutable). Some say tuple is immutable, but at the same time it is somewhat not hashable (throws).
d = dict()
d[ (0,0) ] = 1 #perfectly fine
d[ (0,[0]) ] = 1 #throws
Hashability and immutability refer to object instancess, not type. For example, an object of type tuple can be hashable or not.