1. Home
  2. Data Science
  3. Python
  4. What does the 'finally' block in a 'try-except' statement…

Added 10 Feb 2024

What does the 'finally' block in a 'try-except' statement do?

  1. It defines an alternative condition
  2. It is executed if no exceptions occur
  3. It is always executed, regardless of whether an exception occurs Correct answer
  4. It is used to terminate the program

Correct answer

C. It is always executed, regardless of whether an exception occurs

18 views

MCQSEXAM

Explanation

The finally block always executes, whether or not an exception occurred — and even if the try block returns early. It is used for clean-up such as closing files or database connections.

The block that runs only when no exception occurs is else, a frequent point of confusion.

Keep preparing with more Computer Science MCQs on MCQsExam.com.

Doubts & discussion

Not sure why the answer is C? Ask here and get an explanation.

Ask a doubt about this MCQ

Shown after review. No links please.

More Python MCQs

Practise all Python MCQs

Similar MCQs