Why does the hash function on two different objects return the same value?

I used Spyder, launched Python 2.7.

Just found interesting things:

  • hash (-1) and hash (-2) both return -2, is there a problem? I, although the hash function on another object should return different values. I read the previous posts that -1 is reserved as an error in Python.
  • hash ('s') returns 1835142386, then the hash (1835142386) returns the same value. Is this another problem?

Thank.

+4
source share
1 answer

-1 " " Python. , . , , -1.

" ?" . - . , , . CPython hash() sys.maxint, hash(hash('s')) == hash('s'), .

, -1 -2 , , , , , . Python, . , , , , , .

, , , , , .

+1

All Articles