Normal operation code example :
def finally_test():
try:
pass
print('i am in try start---')
# print(b)
print('i am in try after---')
return 'success'
except:
print('except error ---')
return 'error'
finally:
print("i am finally ---")
if __name__ == "__main__":
res = finally_test()
print("res = {}".format(res))
Output :
i am in try start---
i am in try after---
i am finally ---
res = success
Example of abnormal running code :
def finally_test():
try:
pass
print('i am in try start---')
print(b)
print('i am in try after---')
return 'success'
except:
print('except error ---')
return 'error'
finally:
print("i am finally ---")
if __name__ == "__main__":
res = finally_test()
print("res = {}".format(res))
Output :
i am in try start---
except error ---
i am finally ---
res = error