ProgrammingVery hardProduct-company MCQ pattern

What is printed?

What is printed?
d = {}
d[1.0] = 'x'
d[1] = 'y'
print(d, len(d), d[True])
  1. A. {1.0: 'x'} 1 x
  2. B. {1.0: 'x', 1: 'y'} 2 y
  3. C. {1: 'y'} 1 y
  4. D. {1.0: 'y'} 1 y

Correct answer: D. {1.0: 'y'} 1 y

1 and 1.0 are the same key, so the second assignment replaces the value and keeps the original key object 1.0. Looking up True finds the same key, so it returns 'y'.

More Python Programming questions

Exams that ask this topic