Where do "none"s come from ? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Where do "none"s come from ?

def max(x, y): if x >=y: ### return x print (x) else: ### return y print (y) print(max(4, 7)) z = max(8, 5) print(z)

26th Jul 2017, 5:02 PM
Rong Xiu Chen
Rong Xiu Chen - avatar
5 Answers
+ 1
look in above code u will get output as 7 None 8 None because the function max() is not getting any value in return.. i know it's printing the right answer.. but the second and fourth line of the Output says that... it doesn't get any value from the function {when it reaches outside the function i.e. at line "print (max(4,7))"} 👈this line waits for a value but it gets nothing back from the function.. and the print statement just prints the values.. it doesn't transfers values.. return does that.. now if u just change the code.. as this https://code.sololearn.com/c1QC59f0LlmV/?ref=app then u will find that the if the condition of "if statement" is true then it will "return x" to the function.. and if the condition is false it will "return y"
26th Jul 2017, 5:26 PM
Мг. Кнап🌠
Мг. Кнап🌠 - avatar
+ 1
oh I GOT IT !! Thank u so much !!
26th Jul 2017, 5:39 PM
Rong Xiu Chen
Rong Xiu Chen - avatar
0
since THERE'S no return from the function
26th Jul 2017, 5:05 PM
Мг. Кнап🌠
Мг. Кнап🌠 - avatar
0
sorry... but I'm still confused... what's the different between return and print ?? they look similar to me...
26th Jul 2017, 5:16 PM
Rong Xiu Chen
Rong Xiu Chen - avatar
0
np ;)
26th Jul 2017, 5:53 PM
Мг. Кнап🌠
Мг. Кнап🌠 - avatar