What is the meaning of the astarisk in Python

Andrei see at my.signature.com
Sat Sep 20 21:01:10 EDT 2003


They're both shortcuts for specifying parameters. args is a tuple of
positional arguments, kwargs is a dictionary of keyword arguments.
Like this:



>>> def myfunc(*args):

..     print args

..

>>> myfunc(3,4,"c")

(3, 4, 'c')

>>> def myfunc(**kwargs):

..     print kwargs

..

>>> myfunc(a=3, b=4)

{'a': 3, 'b': 4}

>>> def myfunc(*args, **kwargs):

..     print args, kwargs

..

>>> myfunc(2, 3, c=5, d=6)

(2, 3) {'c': 5, 'd': 6}

>>> myfunc(2, 3)

(2, 3) {}

>>> myfunc(c=5, d=6)

() {'c': 5, 'd': 6}


--
Contact info (decode with rot13): cebwrpg5 at bcrenznvy.pbz
Fcnzserr! Cyrnfr qb abg hfr va choyvp zrffntrf. V ernq gur yvfg, ab arrq gb PP.


Posted via http://dbforums.com




More information about the Python-list mailing list