Python 内建函数 - hash(object)
2017-03-16 09:19
609 查看
Manual
直译
实例
拓展阅读
Note For object’s with custom __hash__() methods, note that hash() truncates the return value based on the bit width of the host machine. See __hash__() for details.
注意:对象自定义的__hash__()方法,hash() 基于主机的位宽来截断返回值,详情见__hash__()。
直译
实例
拓展阅读
Manual
Return the hash value of the object (if it has one). Hash values are integers. They are used to quickly compare dictionary keys during a dictionary lookup. Numeric values that compare equal have the same hash value (even if they are of different types, as is the case for 1 and 1.0).Note For object’s with custom __hash__() methods, note that hash() truncates the return value based on the bit width of the host machine. See __hash__() for details.
直译
返回object的哈希值(如果它有一个的话)。哈希值是整数,它们用于在字典查找时快速匹配字典键。相等的数字值具有同样的哈希值(即便它们属于不同的类型,例如1和1.0)注意:对象自定义的__hash__()方法,hash() 基于主机的位宽来截断返回值,详情见__hash__()。
实例
>>> class CSDN: def foobar(self): print('Hello CSDNer!') >>> hash(CSDN) 4561779 >>> class CSDN: def __init(self): self.name = 'CSDNer' self.nick = 'Fans' self.color = 'Red' def __hash__(self): return hash((self.name, self.nick, self.color)) def foobar(self): print('Hello CSDNer!') >>> hash(CSDN) 4561807
拓展阅读
__hash__()相关文章推荐
- Python函数参数传递方式(call by object reference)以及一致性
- Python标准库:内置函数hash(object)
- Python 内建函数 - id(object)
- Python 内建函数 - setattr(object, name, value)
- Python 内建函数 - repr(object)
- python string hash 函数
- Python 内建函数 - vars([object])
- Python 内建函数 - hasattr(object, name)
- Python 内建函数 - getattr(object, name[, default])
- Python 内建函数 - super([type[, object-or-type]])
- 【转】Python 里的 super() 函数和 object.__new__ ()、.__del__() 方法
- python中使用zip函数出现<zip object at 0x02A9E418>
- Python 里的 super() 函数和 object.__new__ ()、.__del__() 方法
- Python 内建函数 - help([object])
- Python 内建函数 - callable(object)
- Python标准库:内置函数hash(object)
- python中使用zip函数出现<zip object at 0x02A9E418>
- python中使用zip函数出现<zip object at 0x02A9E418>
- Python 内建函数 - iter(object[, sentinel])
- Python 内建函数 - type(object)