Would you, pleace, make clear the differences between:
- parameters (e.g.
def f-n(param1, param2):
)
- parameters which are set by default (e.g.
def f-n(param1 = value, param2 = value2)
)
- Keyword arguments (e.g.
f-n(kwa = value, kwa2 = value2)
)
- positional arguments (e.g.
f-n(pa1, pa2)
)
I’m confused, what is what and where is what.
Thank you so much.
1 Like
This is much later but I wanted to clarify for anyone confused by the same thing.
The difference between a parameter and an argument is where it is. Parameters are placeholder variables that are used when defining a function so that later the function can take inputs when called. Arguments are the term for when we provide values while calling the function. Remember that defining a function uses def
and doesn’t actually run the function, calling the function happens later using parenthesis like function()
.
A parameter can be given a default value param1 = value
(in the above question), in which case it is optional to use it as an argument. If that parameter is not provided a value when it is being called, then it will use the default.
Keyword Arguments are a way to specify a specific parameter to assign a value to rather than doing them all in order. This is very useful when you are dealing with a function that has 10+ parameters, such as when using graphing functions.
Anyways, hope this helps!
21 Likes
while you are defining function the variables given in parenthesis after function name are called parameters,
and when we call that function with values to the parameters are called arguments
Function Definition
def function(parameter1, parameter2):
pass
Function calling
function(argument1, argument2)
7 Likes