ProgrammingVery hardJEE Advanced · CAT placement

What is printed?

What is printed?
print(hash(-1) == hash(-2), hash(-1), hash(2**61 - 1))
  1. A. False -1 0
  2. B. True -2 0
  3. C. True -1 1
  4. D. True -2 2305843009213693951

Correct answer: B. True -2 0

CPython reserves -1 as an error marker for hashes, so hash(-1) is -2, which is also hash(-2). Integers are hashed modulo 2**61 - 1, so 2**61 - 1 hashes to 0.

More Python Programming questions

Exams that ask this topic