Question 3
Back to Exercise
A KeyError is raised. The clauses are except LookupError and then except KeyError. Which runs?
- A except KeyError – the most specific wins
- B Both
- C Neither
- D except LookupError – the first matching clause wins Correct
Correct Answer: Option D
KeyError is a subclass of LookupError, so the first clause matches. Put specific clauses first.
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!