try, except and finally in python

73 Views Asked by At
def finding(a,b):

    try:
        result=a+b
        return result
    except TypeError:
        return "please type only num"
    finally:
        return "this line will get print at last"

print(finding (5, 2)) 

I'm getting the output from the finally, but I'm not getting the output from the try.

1

There are 1 best solutions below

3
Tanner On

Change your last two returns to print statements:

def finding(a,b):

    try:
        result=a+b
        return result
    except TypeError:
        print("please type only num")
    finally:
        print("this line will get print at last")

print(finding (5, 2))