Bird
Raised Fist0

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

easy🧠 Conceptual Q11 of Q15
Python - Advanced Exception Handling
What does the finally block do in a try-except-finally structure?
AIt always runs, whether an error occurs or not.
BIt runs only if an error occurs.
CIt runs only if no error occurs.
DIt runs before the <code>try</code> block.
Step-by-Step Solution
Solution:
  1. Step 1: Understand the role of try and except

    The try block runs code that might cause an error, and except runs only if an error happens.
  2. Step 2: Understand the finally block behavior

    The finally block always runs after try and except, no matter if an error occurred or not.
  3. Final Answer:

    It always runs, whether an error occurs or not. -> Option A
  4. Quick Check:

    finally always runs = A [OK]
Quick Trick: Remember: finally always runs last, no matter what. [OK]
Common Mistakes:
MISTAKES
  • Thinking finally runs only on errors
  • Confusing except and finally blocks
  • Believing finally runs before try

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes