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

19 comments sorted by

View all comments

Show parent comment

2

u/Rangerdth Apr 26 '24

The print statement is printing the “return” from the add method. You send two numbers to the “add” method, which multiplies them and returns the result - then the print statement is run with the returned value.