ProgrammingHardTCS CodeVita · Infosys HackWithInfy

What is printed?

What is printed?
print({**{'a': 1, 'b': 2}, 'a': 3})
  1. A. {'a': 1, 'b': 2}
  2. B. {'b': 2, 'a': 3}
  3. C. {'a': 3, 'b': 2, 'a': 1}
  4. D. {'a': 3, 'b': 2}

Correct answer: D. {'a': 3, 'b': 2}

In a dict display the later value for a repeated key wins, and the key keeps the position of its first insertion. So 'a' stays first with value 3.

More Python Programming questions

Exams that ask this topic