747

4 分钟

#Python 的内置函数 hash

说明:获取哈希值。

#函数说明

def hash(obj): ''' 获取哈希值 :param obj: 一个对象 :return: 对象的哈希值 '''

说明

通过调用对象的 __hash__ 方法,获取对象的哈希值。这个值被用作 dictsetfrozenset 的唯一键。

参数

  • obj - 要获取哈希值的对象

返回值

对象的哈希值。

#示例

print(hash(0)) print(hash(233)) print(hash(3.1415926)) print(hash('')) print(hash('hello world'))

>>> Establishing WebAssembly Runtime.

>>> Standby.

Powered by Shift.

#推荐阅读

创建于 2025/6/9

更新于 2025/6/10