🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← Quiz: Python Dictionaries: all 15 questions

Quiz: Python Dictionaries · Question 6 of 15

What does this print? (code)

What does this print?

d = {"a": 1}
d["b"] = 2
d["a"] = 5
print(d)
  1. A.{'a': 1, 'b': 2}
  2. B.{'a': 5, 'b': 2}
  3. C.{'a': 1, 'a': 5, 'b': 2}
  4. D.An error
Answer & explanation

Correct answer: {'a': 5, 'b': 2}

Assigning to an existing key replaces its value.

Can you get the rest right without peeking?

Take the timed Quiz: Python Dictionaries quiz free. Pass it to earn XP and count towards your certificate.

Start the quiz →