+ 1

What's the different between return and print in function?

suppose that i have def test(x,y): if x>y: print(x) else: print(y) def test2(x,y): if x>y: return x else: return y test(5,6) # result 6 print(test(5,6)) # result 6 and None test2(7,9) # nothing print(test2(7,9) # resullt 9 i want to ask why the result is none?

5th Dec 2019, 9:00 AM
asdsadqw4yhytiujtyu6 asdas
asdsadqw4yhytiujtyu6 asdas - avatar
2 Answers
0
print(test(5,6)) will print 6 None The function test(5,6) itself prints 6. Since it has no return specified, None is returned by default. That is printed by the print command. test2(7,9) does not print anything, it only returns 9 which is not used at all. This is also why print(test2(7,9)) prints 9.
5th Dec 2019, 9:09 AM
Kishalaya Saha
Kishalaya Saha - avatar