In the following method definitions, what does the * and ** do for param2?


The *args and **kwargs is a common idiom to allow arbitrary number of arguments to functions as described in the section more on defining functions in the Python documentation.

The *args will give you all function parameters as a tuple:

The **kwargs will give you all keyword arguments except for those corresponding to a formal parameter as a dictionary.

Both idioms can be mixed with normal arguments to allow a set of fixed and some variable arguments:

Another usage of the *l idiom is to unpack argument lists when calling a function.

In Python 3 it is possible to use *l on the left side of an assignment (Extended Iterable Unpacking), though it gives a list instead of a tuple in this context:

Also Python 3 adds new semantic (refer PEP 3102):

Such function accepts only 3 positional arguments, and everything after * can only be passed as keyword arguments.