Reputation: 13
I am new to learning python, and i want help with the output of this program to understand the return function well.
def Simba(num1, num2):
num1 = Timon(1 + num2 * 3, num1 // 4)
print('Simba', num1, num2)
def Timon(num1, num2):
num1 = Pumba(num2, num1)
num2 = Pumba(num1, num2)
print('Timon', num1, num2)
return num2
def Pumba(num1, num2):
print('Pumba', num1, num2)
return num1
Simba(13, 4)
Upvotes: 0
Views: 76
Reputation: 549
Returning a value means that when you call a function, the value it returns can be used further in the code (for example, by assigning it to a variable).
You are calling the function Simba() with parameters 13 and 4.
Simba() assigns the return value of Timon() to the variable num1.
Looking at the Timon() function, you can see that it returns num2, which means that whatever value num2 is equal to in Simon() will be assigned to num1 in Simba().
Upvotes: 2