Tuesday, March 13, 2018

Variable-length Arguments


Variable-length Arguments in Python 3


You may need to process a function for more arguments than you specified while defining the function. These arguments are called variable-length arguments and are not named in the function definition, unlike required and default arguments.


Syntax for a function with non-keyword variable arguments is given below

deffunctionname([formal_args,] *var_args_tuple ):
    "function_docstring"
    function_suite
    return [expression]

An asterisk (*) is placed before the variable name that holds the values of all nonkeyword variable arguments. This tuple remains empty if no additional arguments are specified during the function call.


 Following is a simple example-


and the output is :