ProgrammingVery hardTCS CodeVita · Infosys HackWithInfy

What is printed?

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

Correct answer: C. 2 True

0.0 and -0.0 compare equal and have the same hash, so the set keeps one of them. Equal numbers always hash equal in Python, so 1, 1.0 and True share one hash.

More Python Programming questions

Exams that ask this topic