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.
一个对象的哈希性是指在生命周期内不可改变(内置__hash__()方法),并且可以和其他对象比较(内置__eq__()方法),当这两个对象相等的时候具有相同的哈希值。
Hashability makes an object usable as a dictionary key and a set member, because these data structures use the hash value internally.
具有哈希性的对象才可作为字典的key和set的成员。
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().
所有不可改变的内置对象都是哈希的,可变的集合不具有哈希性(list、dictionary)用户自定义类的实例默认具有哈希性,而他们的哈希值重他们id性质中来。
本文深入探讨了Python中对象的哈希性概念,解释了什么类型的对象是可哈希的,以及它们如何用于字典和集合数据结构。文章还讨论了用户自定义类实例的默认哈希行为。
8601

被折叠的 条评论
为什么被折叠?



