class test: def __init__(self,name): self.name = name obj1 = test('a') obj2 = test('a') hash1 = magicHash(obj1) hash2 = magicHash(obj2)
__hash__
class test: def __init__(self,name): self.name = name def __hash__(self): return hash(self.name) >>> hash(test(10)) == hash(test(20)) False >>> hash(test(10)) == hash(test(10)) True