ProgrammingModerateTCS NQT · Wipro pattern

What is printed?

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

Correct answer: C. ('b', 2) {'a': 1}

popitem removes and returns the last inserted pair, b, before d is printed, so the printed dict no longer contains b.

More Python Programming questions

Exams that ask this topic