+ 1

Return vs Print

What is the difference between print function and return keyword in Python language? Please explain me it elaborately with example. Please help.

28th Aug 2020, 10:20 AM
Shakibur Rahaman
Shakibur Rahaman - avatar
3 ответов
+ 3
in the context of functions. you either return the value or print it. ie: def sum_fun(x, y): return x + y if you want to print the result you have to use print outside of the function. like : print(sum_fun(4, 6)) #2nd scenario def sum_fun(x, y): print( x + y) now you can call the function without printing because it is included in the function. like : sum_fun(4 + 6) so it depends on how you want to output the result. either using the function itself or by using print .
28th Aug 2020, 10:36 AM
Bahhaⵣ
Bahhaⵣ - avatar
+ 2
Bahha🐧 Yeah I understand.thank u. But why need return keyword?
28th Aug 2020, 10:39 AM
Shakibur Rahaman
Shakibur Rahaman - avatar
+ 2
because sometimes you just need the result without the need to print it. not every function has to print its result.
28th Aug 2020, 10:44 AM
Bahhaⵣ
Bahhaⵣ - avatar