An argument is any piece of data that is passed into a function when the function is called. A parameter is a variable that receives an argument that is passed into a function.
If
a function needs to receive arguments when it is called, the function must have
with one or more parameter variables. A parameter variable, often simply
called a parameter, is a special variable that is assigned the value of
an argument when a function is called. A function may not take any parameters, may
take one parameter or take multiple parameters.
Example:
In
addition to this conventional form of argument passing, the Python language
allows you to write an argument in the following format, to specify which
parameter variable the argument should be passed to:
parameter_name=value
In
this format, parameter_name is the name of a parameter variable and
value is the value being passed to that parameter. An argument that is written
in like this syntax is known as a keyword argument.
Example:
It
is possible to mix positional arguments and keyword arguments in a function
call, but the positional arguments must appear first, followed by the keyword
arguments. Otherwise an error will occur.
show_interest(10000.0,
rate=0.01, periods=10)
In
this statement, the first argument, 10000.0, is passed by its position to the
principal parameter. The second and third arguments are passed as keyword
arguments.
#
This will cause an ERROR!
show_interest(1000.0,
rate=0.01, 10)
because
a non-keyword argument follows a keyword argument.