Why does this work?


#1

I have no idea why does this code works. This return 18 which is the sum of m and n but, how does pyton knows to change the values of m and n for x and y?

m = 5
n = 13
def add_function(x, y):
    suma = (x + y)
    return suma
print add_function(m, n)

#2

You simply assigned the function which had two parameters with values, which is right. But those values were assigned to m and n.

Actually, this works in many, if not all, scripting languages. :slight_smile:


#3

Its kind of confusing, but i guess its really useful once you learn how to use them properly. thanks for the answer :smiley:


#4

You're welcome.

code on!


#5

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.