Write a function that returns a try in the last print statement in finnaly, the code is as follows
DEF fun1 (): x =. 1 try : Print ( ' the try ' ) x = x +. 1 # when x = x / 0 # of the execution statement, when finally executed, the value of x remains. 4 return Print ( ' the try the return ' , X) the except :
Print ( ' exception ' ) return X the finally : X +. 1 = X + =. 1 Print ( ' the finally executed: ' , X)
Execution results as shown below:
It can be seen, it is in accordance with the execution order of functions try - finally executed in the order, - except
That, finally statement block will always be executed, and if the value will inherit the try block finally in the x, where x is