File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments