Track 9 · Lesson 4 of 11
else and finally
Keep the success path in else, put guaranteed cleanup in finally, and know the exact order in which the clauses run.
You will be able to
- Use else for code that should run only when the try block succeeded
- Use finally for cleanup that must happen whether or not an exception occurred
- Predict the order of try, except, else and finally, including with return
- Keep try blocks small so that except clauses catch only the failures they are meant for
Included with a Formula Quest membership
It has 4 graded exercises with feedback, hints and solutions. Python Quest is included in Formula Quest memberships that cover Python; membership and billing are managed on Formula Quest.
View Formula Quest memberships
Tracks 1 and 2, the first lesson of every track, the playground and the dataset library are free.