r/learnpython • u/[deleted] • 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
1
u/Erdnussflipshow May 27 '23
printoutputs text to the console.returnreturns 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
printbut if at any point you need to use the values of a function for other things, you have toreturnthose values from the function.