ProgrammingModerateTCS CodeVita · Infosys HackWithInfy

What is printed?

What is printed?
d = {'x': 1}
e = d
d = dict(d)
d['x'] = 2
print(e['x'], d['x'])
  1. A. 1 1
  2. B. 2 1
  3. C. 1 2
  4. D. 2 2

Correct answer: C. 1 2

dict(d) builds a new dictionary, so the later update applies only to the new object d. e still refers to the old dictionary, so its value stays 1.

More Python Programming questions

Exams that ask this topic