I have been learning return statements in Functions in Python, but then a question raised, what is the difference between print and return? Both of them return values. So, I tried this, and found the result different? Why is the answer different (pls see the images)? If using the print statement, then none is coming too. There is not a large difference but yeah, there is some. Pls tell, Regards
-
a function not returning anything will return ```None```. a return is generally preferred if you are not changing anything in place. Print will only display the value and cannot be used outside a function – Yash Apr 03 '21 at 10:40
-
You should generally return the result of functions, unless their express purpose in interacting with the user. Let's say you want to print the result of `my_function` plus 3; if you return the value, you can do `print(my_function(x) + 3)`, but if you print it, there's no obvious way of doing it. – koorkevani Apr 03 '21 at 10:41
-
I didn't understood – Dheeraj-Tech Apr 03 '21 at 10:41
-
Does this answer your question? [What is the formal difference between "print" and "return"?](https://stackoverflow.com/questions/7664779/what-is-the-formal-difference-between-print-and-return) – Davinder Singh Apr 03 '21 at 10:41
-
[Please do not upload images of code or program output when asking a question.](//meta.stackoverflow.com/q/285551) – Karl Knechtel Aug 17 '22 at 05:24
2 Answers
Return gives back resulting value from function to the code that called this function (caller).
The caller of the function can do whatever he likes with it, not only printing.
But if you do print inside the function then caller doesn't get anything (he gets None), your function just prints straight away the value.
In your case there is almost no visual difference though, but it doesn't mean there is no logical difference underneath.
When you printed value from function returning nothing then you see extra None on console, because functions without return do return None implicitly and you printed this None.

- 14,883
- 6
- 36
- 69
Print function output the value (whatever it gets either directly or through a function) to the standard output.
In the first screenshot, you are running the function and using print in it, which gives 15 in the output. But as that function isn't returning anything, it's none (or nothing) in the output.
In the second screenshot, function is returning some value which print method gets and output it to the screen.

- 409
- 2
- 8