Python arguments
Python gives you alot of options when it comes to function arguments and parameters. So arguments can be defined in a function signature and also as parameters when calling the function, so those two are relevant here. You can have positional arguments, that are identified solely on the ordered position they are pass in, keyword arguments that are called using the form kwarg=value. Default arguments are the same, but are used when a function is defined:
def add(a=1, b=2)
print(a + b)
In contrast, keyword arguments are what we call the arguments we pass when we call a function
add(a=3, b=4)
>>> 7
They are pretty much the same, but they have different names depending on whether they are in the function definition or being passed as function call. Here, values a and b default to 1 and 2, but in the function call we pass in other values, so a is overridden to 3 and b to 4.
What they have in common is that they must come after positional arguments, this rule is similar to javascript.
def add(a=1, b=2, c)
# throws error because c is positional
What is interesting is the variable length arguments, using either the * to gather into a tuple, or a ** to gather into a dictionary. Can be useful for maintaining backwards compatibility, or if you want to loop through a dictionary in your function. They remind me of the … gather in javascript.Â
def f(a, *pargs, **kwargs): print(a, args, kwargs)
f(1, 2, 3, x=1, y=2)
>>> 1, (2, 3) {‘y’: 2, ‘x’: 1}
These have the opposite effect if you are calling a function than if you are defining one:
 f(*(1, 2), **{‘d’: 4, ‘c’: 3})
# same as f(1, 2, c=3, d=4)
This is useful if you can’t predict the number of arguments that will be passed to a function ahead of time, and will make the call more generic.
To summarize, in thee header it collects any number of arguments, in the call it unpacks any number of arguments.

















