Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 01e4c11

Browse files
committed
Merge 3.5
2 parents 47888da + 509476b commit 01e4c11

1 file changed

Lines changed: 8 additions & 5 deletions

File tree

Doc/reference/datamodel.rst

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1338,11 +1338,14 @@ Basic customization
13381338

13391339
Called by built-in function :func:`hash` and for operations on members of
13401340
hashed collections including :class:`set`, :class:`frozenset`, and
1341-
:class:`dict`. :meth:`__hash__` should return an integer. The only
1342-
required property is that objects which compare equal have the same hash
1343-
value; it is advised to somehow mix together (e.g. using exclusive or) the
1344-
hash values for the components of the object that also play a part in
1345-
comparison of objects.
1341+
:class:`dict`. :meth:`__hash__` should return an integer. The only required
1342+
property is that objects which compare equal have the same hash value; it is
1343+
advised to mix together the hash values of the components of the object that
1344+
also play a part in comparison of objects by packing them into a tuple and
1345+
hashing the tuple. Example::
1346+
1347+
def __hash__(self):
1348+
return hash((self.name, self.nick, self.color))
13461349

13471350
.. note::
13481351

0 commit comments

Comments
 (0)