ProgrammingVery hardTCS NQT · Accenture

What is printed?

What is printed?
print(1 == 1.0, hash(1) == hash(1.0), {1: 'a'}[1.0], True + 1.0)
  1. A. True False a 2.0
  2. B. True True None 2.0
  3. C. True True a 2.0
  4. D. 1 True a 2

Correct answer: C. True True a 2.0

1 and 1.0 are equal, and equal numbers must hash the same, so the dict lookup with 1.0 finds 'a'. True behaves as the integer 1 in arithmetic, and adding 1.0 gives the float 2.0.

More Python Programming questions

Exams that ask this topic