DEF Test (A): try : Print ( ' the this try ... IS ' ) IF A == 0: The raise the ZeroDivisionError ( ' Customize ERRO ' ) # if you try there is no return code executed else return STR (10 / A) # between a plurality of mutually exclusive relationship except except BaseException AS E: Print ( ' the this iS. 1 except ... ' + STR (E)) return ' except. 1 ' exceptE AS the ZeroDivisionError: Print ( ' the this the except 2 ... IS ' + STR (E)) return ' the except 2 ' # the else : Print ( ' the this the else ... IS ' ) return ( ' the else ' ) the finally : # the finally the code, no matter what the circumstances have to perform, even if there is return before! Print ( ' After this is finally ... even if there are also first execution finally return again to perform return! ' ) # before if there is return before return overrides finally, if no then finally with return return 'finally' print('the result is: '+str(test(0)))
1、组合:try-except,try-finally,try-except-else,try-except-finally,try-except-else-finally
2, else the successful implementation of the code is not being given only performed if there is return try else in the code is not executed
3, the relationship between a plurality of mutually exclusive except
4, even if the finally will return code, finally will return the cover before finally return before