Variable-length arguments (*args)
When you want a function to accept any number of positional arguments, prefix a parameter name with a single asterisk *. By convention, we use *args.
Within the function, args is a tuple containing all the positional arguments passed.
Variable keyword arguments (**kwargs)
To accept any number of keyword arguments, prefix a parameter name with a double asterisk **. By convention, we use **kwargs.
Within the function, kwargs is a dictionary mapping the parameter names to their values.
Mixing *args and **kwargs
You can use standard arguments, *args, and **kwargs in the same function.
Positional-only parameters (/)
Introduced in Python 3.8, the forward slash / indicates that the parameters before it must be passed as positional arguments, and cannot be passed as keyword arguments.
Keyword-only parameters (*)
To enforce that certain parameters can only be passed as keyword arguments, place an asterisk * in the parameter list. Every parameter after the * must be passed as a keyword argument.
What’s next?
Now let’s learn how nested functions work, how variable scopes are resolved via the LEGB rule, and how to use the global and nonlocal keywords!Scopes & Nested Functions
Learn about nested functions and variable scopes