How a Function Returns Two Values?

0

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)

Output:

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


   


 

Post a Comment

0Comments
Post a Comment (0)