what does *x as a in argument of a method?
Erik Max Francis
max at alcyone.com
Fri May 16 00:18:15 EDT 2003
zeallous wrote:
> What does the *x mean in the following example?
>
> def f(*x):
> return reduce( lambda a, b: a+b, x)
It means that x will get all of the arguments to the function. The nice
thing about Python is that since it's got an interactive interpreter you
can fiddle with these things and find out for yourself:
>>> def f(*x): print x
...
>>> f(1)
(1,)
>>> f(1, 2, 3)
(1, 2, 3)
>>> def g(**y): print y
...
>>> g(a=1, b=2, c=3)
{'a': 1, 'c': 3, 'b': 2}
>>> g()
{}
>>> g(1)
--
Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/
__ San Jose, CA, USA && 37 20 N 121 53 W && &tSftDotIotE
/ \ Principles have no real force except when one is well fed.
\__/ Mark Twain
More information about the Python-list
mailing list