Python函数输入

时间:2015-01-24 16:47:14

标签: python function arguments

我想将函数的输出设置为其他函数的输入, 像这样

def math(a,b):
some code...
return(a,b,c)

def pro(a,b,c):
some code
return(e)
#and then call function by:
pro(math(a,b))

然而,

  

TypeError:pro()缺少2个必需的位置参数:'b'和'c'

你能告诉我如何更改我的代码吗?

2 个答案:

答案 0 :(得分:0)

只需使用星号:

pro(*math(a,b))

答案 1 :(得分:0)

您可以将返回的值解压缩为参数:

args = math(3, 4) # returns (a, b, c)
print pro(*args) # pro(a, b, c)