r/pythonhelp • • Apr 26 '24
Why does this code work? NSFW
def add(num1, num2):
return num1 * num2
def main():
print(add(1,1))
print(add(2,4))
print(add(10,10))
main()
I dont understand how the math in the middle become the arguments for the first function, like how. I can not figure out.
Looking forward to find the solution
2
Upvotes
View all comments
Show parent comment
1
u/kitten1323 Apr 26 '24
Hey, not sure if I’ll be able to help much, but the add() function is being called by the print statement.
So when you do print(add(2, 3)) that’s using the print statement to call add with 2 and 3 as the arguments.
I hope I explained that in a way that makes sense.
It can take a while to grasp some of this. I remember having a really hard time when I started learning.
Hang in there and I promise it eventually clicks.