0

functions and arguments

IM new overhere: def max(x, y): if x >=y: return x else: return y print(max(4, 7)) z = max(8, 5) print(z) """""""""SO yeah in this program why is there print(max(4, 7)) yah I also tried to remove that but its print only 8..BUT ACTUAL OUPUT IS:7,8

27th Jul 2020, 9:06 PM
sayyed usman
sayyed usman - avatar
3 odpowiedzi
+ 1
def max(x, y): if x >=y: return x else: return y These lines are function, defination to find maximum between x and y. (You know this? Otherwise read about functions,) To find max by that function or to use that function, first we need to call it by passing required parameters. So max(4,7) is the call to that function. You read function again, it is return x if x is big. return y if y is big. So you need to print or store this returned value to see or use. By print( max(4,7)), first it call max(4,7) and returned value will be printed by print. I.e 7 Next returned value by calling max(8,5), you are storing in z as z=max(8,5). So z contains 8.then you printing as print(z) Hope you understand it... For more, read about functions, return statements.. Edit: sayyed usman OK you're welcome..
27th Jul 2020, 9:34 PM
Jayakrishna 🇮🇳
+ 1
max(x, y) returning value, that is in first way you directly printing by print(max(4,7)) i.e 7 In next, your storing returned value in z, then printing i.e 8.
27th Jul 2020, 9:12 PM
Jayakrishna 🇮🇳
0
THNKS SIR GOT IT
27th Jul 2020, 9:34 PM
sayyed usman
sayyed usman - avatar