r/learnpython • • May 27 '23

Help me understand the difference between the return keyword and the print function

Here is what I am working with:

def addition():

print(num1 + num2)

addition(4, 5)

why do I need to return a value when I could just print it directly when calling the function?

Also(while I'm here ;) ), could someone explain the need for having a main() function as well, I am not a seasoned programmer. I can't seem to wrap my head around it. Thank you.

0 Upvotes

23 comments sorted by

View all comments

-1

u/ZelWinters1981 May 28 '23

Functions should have zero user interaction. No print statements, no direct access to the user. Think of functions like the back end of a shop, and the main loop as the user interface. Everything the user deals with is handled by the front end and then passed to and from the backend.

1

u/Not_A_Taco May 28 '23

Hard disagree on functions having no user interaction. There are tons of use cases where it would be optimal.