+ 1

Observe the calling process of these two fubctions.

#function 1. def my_func(): print("span") print("spam") print("spam") my_func() #function 2. def max (x,y) if x>=y: return x else: return y: print(max(4,7)) In the last line of the #function 1. The keyword "print" is not required for calling the function. But in the last line of #function 2. Why is the keyword "print" necessary for calling the function.i mean can i just called it by writing max(4,7).

29th Jul 2017, 6:14 AM
stephen haokip
stephen haokip - avatar
2 ответов
0
yes you can call it just by writing max(4,7), but it won't write anything on the screen. that's because inside function1 there are already some print and it doesn't​ return anything. instead function2 returns a value but doesn't print anything, so you need a print to print 7. for example you can assign the value of max(4,7) to a variable like this a=max(4,7) and a will have the value of 7
29th Jul 2017, 8:39 AM
Matte
Matte - avatar
0
Won't the variable a not allow you to call it globally in the rest of the code? That is its self contained within the function?
2nd Aug 2017, 11:43 PM
Anthony Alvarez
Anthony Alvarez - avatar