__hash__() should return an integer. The only required property is that objects which compare equal have the same hash value; it is advised to somehow mix together the hash values for the components of the object that also play a part in comparison of objects
If a class defines mutable objects, it should not implement __hash__(), since hashable collection implementations require that a object's hash value is immutable
__hash__ may now be set to None to explicitly flag instances of a class as unhashable,此外,为了保证对象的哈希的唯一性,一般来说:
def __hash__(self):
return id(self)
No comments:
Post a Comment