ProgrammingHardProduct-company MCQ pattern

What is printed?

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

Correct answer: A. {1: 'c'}

1, 1.0 and True are equal and have the same hash, so they are the SAME dict key. The first key object (1) is kept and its value is overwritten twice, ending as 'c'.

More Python Programming questions

Exams that ask this topic