Post

@Python_Dv B) 2
This is BAD practice in fact
› finally's return 2 overrides try's return 1
› finally ALWAYS executes
› Returns in finally override everything
For beginners:
› Use finally for cleanup (close files, etc.)
› Never return from finally -- it masks other returns!
English

@Python_Dv It prints 2.
In Python, the finally block always runs, even if try already returned a value.
So this happens step by step:
try returns 1
But before leaving the function, finally runs
finally returns 2 and overrides the previous return
So:
print(test())
outputs:
2
English

@Python_Dv Haven't seen "try" and "finally".
I've only seen "if, elif, else".
See you there soon.
English

@Python_Dv B) 2
finally always runs, even after return.
It overwrites the return value. Python's way of saying "I wasn't done yet"
English

@Python_Dv Answer: B) 2
finally always executes and overrides any return in try.
So even though try returns 1, the return 2 in finally wins.
English

@Python_Dv It prints 2 but if I see this I’m going to go into a corner and cry for a week
English

@Python_Dv I do believe it returns None.
Blocks of exceptions does not support the statement "return", so by default the function will return NoneObject
English

@Python_Dv 2
In try, except, else and finally construct, finally block is always executed.
Here first try is executed and return 1. Then finally is executed and it returns and overwrites 1 thus printing 2
English









