[Tutor] arguments

Gregor Lingl glingl at aon.at
Thu Feb 15 14:26:12 CET 2007

emilia12 at mail.bg schrieb:

>Hi list,
>I have a function with two arguments (say f(x,y))
>and second which returns tuple (say def g(): return (xx,yy))
>my question is how to put returned values from g() as
>arguments to f ?
There is a special *-operator, which inserts the components of an Argument
(which must be a sequence) into the parametersof the calling function:
 >>> def f(x,y):
    print x,y

 >>> def g():
    return -5,1001

 >>> f(*g())
-5 1001

>the direct way generates error:
>TypeError: ff() takes exactly 2 arguments (1 given)
>and the hard way is
>x, y = g()
>is ok but it uses two extra variables. Is there a simple way
>to do this?
>BTW f(g()[0], g()[1]) works too, but calls function g()
>twice ...
>thanks in advance
>SCENA - Единственото БЕЗПЛАТНО списание за мобилни комуникации и технологии.
>Tutor maillist  -  Tutor at python.org

More information about the Tutor mailing list