I tried googling it but couldn't find a similar problem. I am sure it's something silly but I can't seem to get it.
I have the following code:
def f(a):
try:
4 / a
except:
f(2)
else:
print('else')
finally:
print("finally")
When I call the function with 0 as the argument: f(0)
It returns:
else
finally
finally
So in my understanding here is what should happen:
- 0 gets fed to the function;
- try statement can't execute it;
- except statement gets triggers, which calls the function again with a legal argument, 2.
- try statement is now okay;
- else statement prints
else - finally statement prints
finally
Why does finally gets printed twice?