Step-by-step Explanation:
try block runs first:
This means the function intends to return 1.
-
But there's a finally block:
The finally block always executes, whether or not there’s an exception.
-
In Python, if both try and finally have return statements, the return value from finally overrides the one from try.
✅ So what happens?
try wants to return 1
finally runs and replaces that with 2
Final Output:
Important Rule:
If a finally block contains a return, it overrides any return or exception from the try or except blocks.


0 Comments:
Post a Comment