Can someone please explain me why does this work like it does? Python 3.6.3
In [1]: def test():
...: try:
...: return 1
...: finally:
...: return 2
...:
In [2]: test()
Out[2]: 2
EDIT:
This is not exactly duplicate as linked questions raise exceptions in their try :
and my example uses return
which I expected to work. This function looks like it should return 1 yet it returns 2 - so basically return 1
is ignored. finally
makes a good job of eating any risen exceptions but should it also eat returns?