hash() method in python can match all immutable objects to unique hash value. However, I cannot understand the behavior of hash() method for objects of user-defined classes. Some of the resources say that if user-defined class do not contain __hash__()
and __eq__()
methods, that object cannot be hashed. On the other hand, the others claim the opposite one.
In other words, what is the role of __eq__()
and __hash__()
methods in order to hash custom objects ?