🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← Quiz: The collections Module: all 10 questions

Quiz: The collections Module · Question 10 of 10

What is the risk of writing if d[key]: on a defaultdict just to check a key?

What is the risk of writing if d[key]: on a defaultdict just to check a key?

  1. A.It raises KeyError
  2. B.It deletes the key
  3. C.It creates the key with a default value as a side effect
  4. D.It converts the defaultdict to a dict
Answer & explanation

Correct answer: It creates the key with a default value as a side effect

Use key in d to check without adding anything.

Can you get the rest right without peeking?

Take the timed Quiz: The collections Module quiz free. Pass it to earn XP and count towards your certificate.

Start the quiz →