Reputation: 8030
According to the doc:
Objects which are instances of user-defined classes are hashable by default; they all compare unequal (except with themselves), and their hash value is their id().
Now from console:
class ABC:
def __init__(self):
pass
a = ABC()
id(a)
140102888165648
hash(a)
8756430510353
Shoudln't a
have the same hash and id value?
Upvotes: 2
Views: 112
Reputation: 101919
According to the documentation for __hash__()
User-defined classes have
__cmp__()
and__hash__()
methods by default; with them, all objects compare unequal (except with themselves) andx.__hash__()
returns a result derived fromid(x)
.
It seems like the glossary is either outdated or inaccurate.
The documentation for python3's __hash__
is slightly different:
User-defined classes have
__eq__()
and__hash__()
methods by default; with them, all objects compare unequal (except with themselves) andx.__hash__()
returns an appropriate value such thatx == y
implies both thatx is y
andhash(x) == hash(y)
.
So they even removed the fact that such value should depend on id
.
Upvotes: 3