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/lukajda33 May 27 '23
You only use print if you want to show something to the user of the program, but usually you just want to calculate something and use it later in the program.
Lets say you had a program to calculate discount and tax for selling some product, you could have a function to calculate discount, another to calculate tax. You would return the result from the function in order to subtract or add it from total cost, but you would print only the final price to the user.