I have the following sample function:
def test():
try:
try:
x =1
except:
x = 2
finally:
print('X')
x = 7
return x
except Exception:
x=2
finally:
x = 9
return x
print(test())
Based on this, I would expect that test() always returns 7 (first return), but instead it returns 9, even though it reached the x=7 line ('X' is printed). How can this be?