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

Consider the following Python code: d = {"a": 1, "b": 2}; d["a"] = d["b"]. What will be the value of d after execution?

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-663C98

Consider the following Python code: d = {"a": 1, "b": 2}; d["a"] = d["b"]. What will be the value of d after execution?

  1. A.{"a": 1, "b": 2}
  2. B.{"a": 2, "b": 2}Correct answer
  3. C.{"a": 2, "b": 1}
  4. D.{"a": 1, "b": 1}

Solution

The expression d["b"] evaluates to 2, and this value is assigned to the existing key "a". Thus, the dictionary becomes {"a": 2, "b": 2}.

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