Next / Previous / Contents / TCC Help System / NM Tech homepage

8.2. Function argument list features

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 of arguments:

  1. If the argument is just a name, it is called a positional argument. There can be any number of positional arguments, including zero.

  2. You can supply a default value for the argument by using the form “name=value”. Such arguments are called keyword arguments. 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.

  3. 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:

    * name
    

    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”.

  4. 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:

    ** name
    

    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”.