Documentation of __hash__

Richard Damon Richard at Damon-Family.org
Fri Feb 7 10:14:58 EST 2020


On 2/6/20 2:13 PM, klauck2 at gmail.com wrote:
> The default __eq__ method (object identity) is compatible with all (reasonable) self-defined __hash__ method.
>
> Stefan

If __eq__ compares just the id, then the only hash you need is the 
default that is also the id. If you define a separate hash function, 
which uses some of the 'value' of the object, then presumably you intend 
for objects where that 'value' matches to be equal, which won't happen 
with the default __eq__.

-- 
Richard Damon



More information about the Python-list mailing list