Python==3.6.9
def test():
a = 2
try:
1 / 0
except Exception as exc:
return a
finally:
a += 1
print(a)
print(test())
output is:
3
2
It's obvious that finally executes before return, if a is a immutable type, id(a) is different between finally scope and try\except scope;
I want to know how did this happen? Thanks