Why should we use the return statement over print() in Python? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Why should we use the return statement over print() in Python?

8th Feb 2021, 1:30 PM
PHILOMATH PRATIK
PHILOMATH PRATIK - avatar
4 Answers
+ 4
Philosophical Coder adding to what Abhay has explained, If you use print in a function, it will output the extra "None" causing the program to behave in an undesirable way
8th Feb 2021, 1:39 PM
CHANDAN ROY
CHANDAN ROY - avatar
+ 2
return is used to return the value back to function call unlike print that prints the value assigned to a variable or value returned by function call . Basically if you wanna use the value from a function at various places , just return the value and assign the function call to a variable .
8th Feb 2021, 1:36 PM
Abhay
Abhay - avatar
+ 2
But you can use the print as well. If you are using print you don't need to print the function. You can just call it . And then you will get the result you want. Please check this code for better understand . https://code.sololearn.com/cdJ7B0zYZ6Iz/?ref=app
8th Feb 2021, 4:24 PM
K.S.S. Karunarathne
K.S.S. Karunarathne - avatar
+ 1
As CHANDAN ROY said ,but only if you print the function call , simply calling function will work fine.
8th Feb 2021, 1:42 PM
Abhay
Abhay - avatar