How a Function Returns Two Values?


How a Function Returns Two Values?

  • In this topic, we learn to a python program to understand how a function returns two values.

Source Code:

# A function that return two results
def sum_sub(a,b):
   """this function returns result of
      addition and subtraction of a,b"""
   c = a + b
   d = a - b
   return c,d
#get the results from the sum_sub() function
x,y = sum_sub(18,16)
#display the results
print("Result of addition : ",x)
print("Result of subtraction : ",y)


  • Result of addition : 34
  • Result of subtraction : 2



Post a Comment

Post a Comment (0)