0

I have a short and simple question.I have been learning python by the Codeacademy website and i came across a section which gives you an exercise.Here is a part of exercise's text:

Below your existing code, define a function called rental_car_cost with an argument called days.

My question is,why does the exercise call days an argument ? isn't is supposed to be a Parameter?

Because an argument is a value which you give it to a function while calling it.

Please help me.Thanks

sshashank124
  • 31,495
  • 9
  • 67
  • 76
user3722727
  • 133
  • 1
  • 1
  • 7
  • 3
    True. That is the more nitty-gritty specifics [(link)](http://stackoverflow.com/questions/156767/whats-the-difference-between-an-argument-and-a-parameter) but in some cases people use it interchangeably without second thought. – sshashank124 Jun 26 '14 at 13:21
  • 1
    i switch between using both all the time. As a argument for using argument (heh) the python default name for variable length argument lists is args , and the named one is kwargs (keyword) – omu_negru Jun 26 '14 at 13:37

4 Answers4

1

For clarification to anyone coming upon this question;

A Parameter is a variable in the declaration of a function:

functionName(parameter) {
    // do something
}

An Argument is the actual value of this variable that gets passed to the function:

functionName(argument);

In relation to your question; Yes the question is improperly worded; unfortunately many people use the names interchangeably.

MikeRixWolfe
  • 430
  • 3
  • 9
0

Don't think too much into it. It's an informal use of the term that's not entirely correct, but still more-or-less accepted. Just assume Codecademy means parameter in this context. Have fun learning!

Cameron
  • 127
  • 10
0

In some cases it is true that you would want to be this precise with how you describe a function/method. If you were designing a spec or overloading a function/method for example, this distinction would be very important. This is because of the way that most languages handle calling a function. Arguments passed to the function are usually sent to a new "stack" where they are assigned to temporary parameter variables while the function is executing. In some languages, functions can be "overloaded" so that the type of the argument (string, int, etc.) can have a dramatic effect on what the function actually does. Because of this, it pays to differentiate between parameters and arguments in certain cases.

However, python does not care about types, so usually this stuff doesn't really matter. In effect, any given number of arguments will be assigned to the same parameters when a function is called, so it's okay to think of them as synonymous. In fact, python will even let you directly assign values to parameters as keyword arguments, dismissing the need for classical argument passing entirely, for example: function(foo=0, bar=1). Moreover, for the purposes of learning the basics of python, the distinction is really unnecessary.

cephalopodMD
  • 169
  • 9
0

See this previous answer, which cites (an old version of) the Wikipedia article on parameters to say this:

The Wikipedia article also states that the two terms are often used synonymously (especially when reasoning about code informally):

Although parameters are also commonly referred to as arguments, ...

In my experience, the term 'argument' is used more often than 'parameter', especially in Python. There is some nuance, since we usually speak of a function 'taking' arguments rather than 'having' them (and 'having' parameters, rather than taking them), but that's getting a bit more pedantic than most programmers like to be.

Community
  • 1
  • 1
lvc
  • 34,233
  • 10
  • 73
  • 98