syntax question

Richard Brodie R.Brodie at rl.ac.uk
Thu Nov 22 17:20:26 CET 2001


"Rajarshi Guha" <rxg218 at psu.edu> wrote in message news:9tj7et$oi2 at r02n01.cac.psu.edu...

> def V(*vals):
>   return array(vals)
>
> I can see that the *vals takes in a tuple - is this orrect or are there any
> other significances of this sytnax?

*vals swallows the end of an argument list and produces a tuple - so can
 be used for printf/stdarg like functions: saves some extra brackets.


>>> def a(*vals):
...  print vals
...
>>> def b(vals):
...  print vals
...
>>> a(1,2,3)
(1, 2, 3)

>>> b(1,2,3)
Traceback (most recent call last):
  File "<interactive input>", line 1, in ?
TypeError: b() takes exactly 1 argument (3 given)

>>> b((1,2,3))
(1, 2, 3)





More information about the Python-list mailing list