Clarification between Argument and Parameter?


#1

After going through some of these lessons I am still hazy on the exact difference between a Parameter and Argument in regards to defining a function? Are they the same thing, just different syntax, or am I missing a larger definition here?

For example, lesson 1.2 on “Taking a Vacation” has you create the function:

def hotel_costs():
return 140 * nights

It says to not use any arguments, but could you also say to not use any parameters?


#2

parameters are added when defining a function, while arguments are supplied at function call:

def example(parameter):
    print parameter

example("argument")

however, we can provide a default value to a parameter in case no argument is supplied:

def example(parameter=None):

now if no argument is provided at function call, the parameter will be None

What we did above (providing default value) is called named argument, so i wouldn’t get hung up too much on the technical naming. Very few programmers will get this right, they are more interested in how to implement.

The only reason i get it right, is because i helped out on the forum, and explaining does require using the right terms


#3

Great way to explain it, that makes a lot more sense now with it broken down. Thank you for that and your help on these forums!


#4

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