>>> class A(object): ... pass ... >>> >>> a = A() >>> b = A() >>> a == a True >>> a == b False >>> id(a) 4343310992 >>> id(b) 4343310928
>>> set().add({})
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: unhashable type: 'dict'
unhashable type: 'dict'
>>> class C:
... def __init__(self, x):
... self.x = x
... def __repr__(self):
... return "C({"+str(self.x)+"})"
... def __hash__(self):
... return hash(self.x)
... def __eq__(self, other):
... return (
... self.__class__ == other.__class__ and
... self.x == other.x
... )
>>> d = dict()
>>> s = set()
>>> c = C(1)
>>> d[c] = 42
>>> s.add(c)
>>> d, s
({C(1): 42}, {C(1)})
>>> c in s and c in d # c is in both!
True
>>> c.x = 2
>>> c in s or c in d # c is in neither!?
False
>>> d, s
({C(2): 42}, {C(2)}) # but...it's right there!
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有