← 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?
- A.It raises KeyError
- B.It deletes the key
- C.It creates the key with a default value as a side effect
- 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 →