finally keyword in python code example
Example 1: python finally
try:
print('Test')
except (SyntaxError, IndexError) as E:
print('Synthax or index error !')
except :
print('Other error !')
else:
print('No error')
finally:
print('Done')
print('Anything else')
Example 2: python finally keyword
try:
x > 3
except:
print("Something went wrong")
else:
print("Nothing went wrong")
finally:
print("The try...except block is finished")
Example 3: finally keyword
It come after try catch block
A finally block of code always executes,
whether or not an exception has occurred.