So let's say I have a function like this:
def dummy():
e = 1
try:
return e
finally:
e = 2
This function returns 1
, so it looks like return
statement is executed before finally
, so finally
has no effect at all.
However, when I declare the function like this:
def dummy():
e = {}
e['x'] = 1
try:
return e
finally:
e['x'] = 2
The returned value is {'x': 2}
, so it looks like finally
is executed before return
.
Could someone explain to me what happens here actually?