ProgrammingVery hardCodeforces-style · placement coding round

What is printed?

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

Correct answer: C. True True

bool is a subclass of int and True equals 1, so their hashes match. In CPython hash(-1) is -2, because -1 is reserved as an error marker.

More Python Programming questions

Exams that ask this topic