Which of the following statements are true about Try-Except-Else clause in Python?
A. Suspicious lines of codes are put inside a try block.
B. The except block is executed if an exception occurs.
C. You can have multiple except block to handle multiple exceptions.
D. The else block is executed when no exceptions are raised.
Which of the following statements are true about Try-Except-Else clause in Python?
A. Suspicious lines of codes are put inside a try block.
B. The except block is executed if an exception occurs.
C. You can have multiple except block to handle multiple exceptions.
D. The else block is executed when no exceptions are raised.
Solution
All four statements are true.
A: Code that may raise an error goes inside the try block.
B: If an exception occurs in try, control jumps to the matching except block.
C: A single try can have several except blocks, each handling a different exception type.
D: The else block runs only when the try block finishes without raising any exception.
Options 1, 2 and 3 each leave out a true statement, so none is complete.
Memory trick: else runs only if try succeeds, and except runs only if try fails, so the two never both run.
Related questions:
2026: 29 May Shift 1
2025: 3 June Shift 2