I've always thought that in cpython hash()
built-in function returns the integer itself for integers. So I was a bit confused, when I found out, that hash(-1)
is an exception to the rule and returns -2.
Is there any reason for hash(-1)
to not be equal -1
Asked
Active
Viewed 133 times
0

Kirill Zaitsev
- 4,511
- 3
- 21
- 29
-
tldr: because `-1` is used to signal errors in underlying C function. full version: http://effbot.org/zone/python-hash.htm – Cong Ma Oct 13 '15 at 17:23
-
Possible duplicate of http://stackoverflow.com/questions/10130454/why-do-1-and-2-both-hash-to-2-in-python – Ahsanul Haque Oct 13 '15 at 17:24