Question 2
Back to Exercise
What is the difference between d["k"] and d.get("k") when "k" is missing?
- A Both return None
- B Both raise KeyError
- C d["k"] raises KeyError; d.get("k") returns None Correct
- D d.get("k") raises KeyError; d["k"] returns None
Correct Answer: Option C
get() also takes a default: d.get("k", 0).
Discussion & Comments 0
Share your method, a shortcut, or ask about a step you didn't follow.
No comments yet. Be the first to share your solution!