Python exception handling

def foo():
try:
return(1)
finally:
return(2)
k=foo()
print(k)

output of the above code is 2. I am not getting the answer, why is it showing 2, please help.

def foo():
try:
return(1)

finally:
    return(2)

k=foo()
print(k)

Note: Use proper indentation then python interprater read it. As try is not proper indented so copy code ndindent it properly