Return in Function

Lesson Progress
0% Complete

Python Functions: Return Statement

Function with return type


def add_two_numbers(x,y):
    return (int(x+y))

print('Calling addition function, by using it in print()\nResult = ',add_two_numbers(3,6))

Python Functions: Without Return Statement

def add_two_numbers(x,y):
    print(int(x+y))


add_two_numbers(3,6))

Python Functions : with *args

def add_two_numbers(*num):
   arg1=num[0]
   arg2=num[1]
   sum = arg1 + arg2
   return sum
a = 5
b = 6

print(f"The sum is\t{add_two_numbers(a, b)}")

Python Functions : with **kwargs

def add_two_numbers(**num):
   arg1=num["a"]
   arg2=num["b"]
   sum = arg1 + arg2
   return sum

print(f"The sum is\t{add_two_numbers(a=5,b=6)}")