The general form of a
def shown in Section 8, “
def: Defining functions” is over-simplified. In general, the
argument list of a function is a sequence of four kinds
If the argument is just a name, it is called a positional argument. There can be any number of positional arguments, including zero.
You can supply a default value for the argument by
using the form “
”. Such arguments are called
See Section 8.3, “Keyword arguments”.
A function can have any number of keyword arguments, including zero.
All keyword arguments must follow any positional arguments in the argument list.
Sometimes it is convenient to write a function that can accept any number of positional arguments. To do this, use an argument of this form:
A function may have only one such argument, and it must follow any positional or keyword arguments. For more information about this feature, see Section 8.4, “Extra positional arguments”.
Sometimes it is also convenient to write a function that can accept any number of keyword arguments, not just the specific keyword arguments. To do this, use an argument of this form:
If a function has an argument of this form, it must be the last item in the argument list. For more information about this feature, see Section 8.5, “Extra keyword arguments”.