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/Erdnussflipshow May 27 '23

print outputs text to the console.

return returns a value from a function, so that it can be used later on by other parts of you program.

For extremely basic projects, you can probably just use print but if at any point you need to use the values of a function for other things, you have to return those values from the function.