+ 1
finally statement.
when finally function work? if there is no error in mathematical operation then finally statement execute or not? try: math=4/4 print(math) except: print("an error occured") finally: print("this code will run no matter what") output of this code is 4 this code will run no matter what tell me why it so?
3 Antworten
+ 5
Are you sure it outputs 4? It should be one.
The try, except, finally block is explained here https://www.sololearn.com/learn/JUMP_LINK__&&__Python__&&__JUMP_LINK/2441/
https://www.sololearn.com/learn/Python/2442/
If in the try block an error occurs, the except block is called.
The finally block is always called, no matter if there was an exception or not
+ 3
Yes the finally section will be executed in the end, regardless if there was an error or not.
+ 1
the output is 1 insted of 4. it is my mistake