ProgrammingVery hardProduct-company MCQ pattern

What is printed?

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

Correct answer: D. True True {1: 'c'}

1, 1.0 and True hash equally and compare equal, so they are the same dict key. The dict keeps the first key object (1) and overwrites its value with 'c'.

More Python Programming questions

Exams that ask this topic