ProgrammingVery hardGATE CS · Product-company placement

What is printed?

What is printed?
d = {0: "zero", False: "F", 0.0: "f", "": "e"}
s = {1, True, 1.0, -0.0, 0}
print(d, len(s))
  1. A. {0: 'zero', False: 'F', 0.0: 'f', '': 'e'} 5
  2. B. {0: 'f', '': 'e'} 2
  3. C. {False: 'f', '': 'e'} 2
  4. D. {0: 'zero', '': 'e'} 2

Correct answer: B. {0: 'f', '': 'e'} 2

0, False and 0.0 are equal and hash the same, so they are one key: the FIRST key object (0) is kept and the LAST value ('f') wins. In the set, 1/True/1.0 collapse to one item and -0.0/0 to another.

More Python Programming questions

Exams that ask this topic