Bird
Raised Fist0

In a try-except-else block, when is the else block executed?

easy🧠 Conceptual Q2 of Q15
Python - Advanced Exception Handling
In a try-except-else block, when is the else block executed?
AOnly if the <code>try</code> block raises an exception.
BOnly if the <code>except</code> block is executed.
CAlways, regardless of exceptions.
DOnly if the <code>try</code> block completes without exceptions.
Step-by-Step Solution
Solution:
  1. Step 1: Review try-except-else execution order

    The try block runs first. If no exception occurs, the else block runs next.
  2. Step 2: Confirm else block condition

    The else block runs only if the try block finishes without errors.
  3. Final Answer:

    Only if the try block completes without exceptions. -> Option D
  4. Quick Check:

    else runs if try succeeds = B [OK]
Quick Trick: Else runs only when try has no errors [OK]
Common Mistakes:
MISTAKES
  • Believing else runs after except
  • Thinking else runs always
  • Confusing else with finally

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes