user3722727
user3722727

Reputation: 133

Parameter vs Arguments ? finally,what are they?

I am a beginner in python programming and recently i came across functions,parameters,arguments and...

I have done a lot of research on Parameters and Arguments(Even checked the answers of similar past questions on StackOverflow)but i couldn't get their meanings.

Some say,parameters are variables which we give them to functions while we are defining them and arguments are values that are passed in function once we given them to the function in order to run the function.While some other say no,it's not like that.Parameters and Arguments are same and do the same task...

Can anyone tell me the meaning Parameters and Arguments in a clear way?

Are Parameters and Arguments considered variables?

For what kind of purpose do we use them?

Please don't explain too much complicated,i am a beginner.

Thank you so much.

Upvotes: 2

Views: 1205

Answers (2)

jonrsharpe
jonrsharpe

Reputation: 121987

Per the official documentation:

Parameters are defined by the names that appear in a function definition, whereas arguments are the values actually passed to a function when calling it. Parameters define what types of arguments a function can accept. For example, given the function definition:

def func(foo, bar=None, **kwargs):
    pass

foo, bar and kwargs are parameters of func. However, when calling func, for example:

func(42, bar=314, extra=somevar)

the values 42, 314, and somevar are arguments.

The glossary defines them as:

  • Argument: A value passed to a function (or method) when calling the function.
  • Parameter: A named entity in a function (or method) definition that specifies an argument (or in some cases, arguments) that the function can accept.

Python doesn't really have "variables" like some other languages - it has "names" referring to "objects". See e.g. "Code like a Pythonista" and "Facts and myths about Python names and values".

Upvotes: 6

mfs
mfs

Reputation: 4074

Take it this way:

Parameter: A parameter represents a value that the procedure expects you to pass when you call it. The procedure's declaration defines its parameters.

Argument: An argument represents the value that you pass to a procedure parameter when you call the procedure. The calling code supplies the arguments when it calls the procedure.

Example:

int add (int value1, int value2)  // Here value1 and value2 are PARAMETERS.
{
return value1+value2;
}

Now while calling the function

answer = add(2,3);  // Here values 2 and 3 are ARGUMENTS. 

Same goes with Python, while declaration, they are parameters, while calling they are arguments.

Some may differ with what i have written, but this is how it is actually known in programming world.

Upvotes: 1

Related Questions