Defining parameters and arguments here could help.
- Parameter: a named entity in the function/method definition that specifies an argument.
- Argument: a value passed to a function.
For example,
def my_function(parameter_1, parameter_2):
pass
my_function(argument_1, argument_2)
Now when you say positional argument, you are talking about arguments, so has nothing to do with the function definition. width
and height
in your example are positional parameters or keyword parameters (so called positional-or-keyword parameters).
How you are calling/passing the value to the function determines if they are positional arguments or keyword arguments.
rectangleArea(1, 2) # positional arguments
rectangleArea(width=1, height=2) # keyword arguments
The thing not many people know is that you can specify a positional-only parameter by using the /
in the parameter list (example from here).
def func(positional_only1, positional_only2, /, positional_or_keyword): ...
Similarly, you can also have keyword-only parameters by using the *
character.
def func(positional_or_keyword, *, keyword_only1, keyword_only2): ...
Finally, we also have var-positional and var-keyword (a.k.a *args and **kwargs respectively). Meaning, you can have arbitrary sequence of positional arguments or keyword arguments passed to the function.