Practice mode Python

When does the finally clause of a try statement execute?

Correct answer D. Always, whether or not an exception occurred in the try block

Explanation

finally runs as the last task before the try statement completes, whether the try block finished normally, an exception was handled, an exception is propagating, or a return, break or continue left the block. That makes it the right place for clean-up such as closing files or releasing locks.

Report a problem

Answer checked How we write and check questions

Tip: press A, B, C or D to answer, and N for the next question.

Advertisement

Have a question about this answer?

Your email address will not be published. Required fields are marked *

Links and website addresses are not allowed in comments.