5. Pull it together


#1

Question: Why is it that they used:

def add(a,b)… and not
def add(n,p)

Very confusing to me.
Thank You!

question


#2

why would you use the same parameter names again? That can become very confusing. Then it becomes very tricky which variables and values are passed down to other functions

a and b are just local variable within the add function, they get there values from arguments at function call:

# defining function with a and b parameters
def add(a, b):
   return double(a) + triple(b)

# calling function, providing arguments (aka values) for parameters
print add(5, 3)

by this logic, we pass a and b as arguments to n and p parameters. I understand why its confusing, but if you understand how parameters and arguments work, it makes more sense (hopefully)


#3

After I posted this I had just realized what i was asking :joy:. Thanks for the explanation!


#4

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