"**" operator in method/function interfaces ??

Fredrik Lundh fredrik at effbot.org
Fri Dec 8 05:51:26 EST 2000


Gilles Lenfant wrote:
> What's the use of "**" in such a construct ?
> <sample>
> ...
> class MyClass:
>     def __init__(self, adata, **anotherdata)
> ...
> </sample>
>
> I found such construct in some examples of the Tkinter tutorial at
> pythonware, and in some other documents.
> I have gone around all books and web language tutorial I know and did not
> find anything about it.

    http://www.python.org/doc/current/ref/function.html

    If the form "*identifier'' is present, it is initialized to
    a tuple receiving any excess positional parameters,
    defaulting to the empty tuple. If the form "**identifier''
    is present, it is initialized to a new dictionary receiving
    any excess keyword arguments, defaulting to a new
    empty dictionary.

or, in other words:

    >>> def func(*args, **kwargs):
    ...     print args, kwargs
    ...
    >>> func(1, 2, 3, a=4, b=5, c=6)
    (1, 2, 3) {'b': 5, 'c': 6, 'a': 4}

</F>





More information about the Python-list mailing list