Tuples and Dictionaries · Class 11 · CBSE · Science Computer Science

What is printed by the following Python code? d = {"a": 10, "b": 20}; d["c"] = d.pop("a"); print(d["c"], len(d))

Practice question from Tuples and Dictionaries (Class 11 · CBSE · Science Computer Science), with the correct answer and a step-by-step solution.

medium · MCQ · Q-0FB868

What is printed by the following Python code? d = {"a": 10, "b": 20}; d["c"] = d.pop("a"); print(d["c"], len(d))

  1. A.10 2Correct answer
  2. B.20 3
  3. C.10 3
  4. D.a 2

Solution

d.pop("a") removes the key "a" and returns its value, 10. This value is assigned to the new key "c", so the dictionary still contains two items and d["c"] is 10.

More from Tuples and Dictionaries

All of Tuples and Dictionaries

Practise more Computer Science

Sign up free for adaptive practice on this chapter, with instant feedback and hints on every question.

Start practising free

Free to start · No credit card needed