Python 返回对象哈希值
Python 返回对象哈希值的例子
返回对象哈希值
# Filename : example.py
# DateTime : 2020-07-20
# author by : www.lidihuo.com
class Lidihuo():
def __init__(self,name,url):
self.name = name
self.url = url
lidihuo = Lidihuo('lidihuo','www.lidihuo.com')
print(hash(Lidihuo))
运行结果:
list, dict, set等可变对象都不可哈希(unhashable):
# Filename : example.py
# DateTime : 2020-07-20
# author by : www.lidihuo.com
print(hash([1,3,5]))
Traceback (most recent call last):
File "script.py", line 5, in
print(hash([1,3,5]))
TypeError: unhashable type: 'list'