Predict try/except/finally
Predict Output Medium
Question
What does this code print?
Code
try:
x = 1 / 0
except ZeroDivisionError:
print("caught")
finally:
print("done")
Hint
finally always runs, whether or not an exception occurred.
Explanation
1 / 0 raises ZeroDivisionError. The except block catches it and prints 'caught'. The finally block always runs, so it prints 'done'. Output: caught then done.
Related Resources
Related Lessons
- Exceptions
try/except/finally.
Look up unfamiliar terms
A beginner-friendly glossary explains jargon in plain English — variables, functions, DOM, Promise, and more.
Decode error messages
Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.
Build real projects
Apply what you learned by building guided projects with starter code and solutions.