[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
>>>
Regards,
Gregor
>the direct way generates error:
>
>f(g())
>TypeError: ff() takes exactly 2 arguments (1 given)
>
>and the hard way is
>x, y = g()
>f(x,y)
>
>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
>e.
>
>
>
>-----------------------------
>
>SCENA - Единственото БЕЗПЛАТНО списание за мобилни комуникации и технологии.
>http://www.bgscena.com/
>
>_______________________________________________
>Tutor maillist - Tutor at python.org
>http://mail.python.org/mailman/listinfo/tutor
>
>
More information about the Tutor
mailing list