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__() method). Hashable objects which compare equal must have the same hash value.
Hashability makes an object usable as a dictionary key and a set member, because these data structures use the hash value internally.
All of Python's immutable built-in objects are hashable; mutable containers (such as lists or dictionaries) are not. Objects which are instances of user-defined classes are hashable by default. They all compare unequal
(except with themselves), and their hash value is derived from their id().
如果一个对象在其生命周期内,有一个固定不变的哈希值(__hash__()方法)并且可以跟其他对象进行比较(__eq__()方法),那么该对象是可哈希的。比较结果相等的可哈希对象必须有相同的哈希值。
散列性(哈希)使对象可用作字典键值和集合元素,因为这些数据结构在内部使用散列值。
所有python内置的不可变对象都是可哈希的;同时,可变容器都是不可哈希的。默认情况下,用户自定义类的实例对象是可哈希的,这些实例对象各不相同,并且各自的哈希值都由id()方法派生得出。