【问题标题】:Python function input [duplicate]Python函数输入[重复]
【发布时间】:2015-03-23 13:10:44
【问题描述】:

我想将一个函数的输出设置为另一个函数的输入, 像这样

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'

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

【问题讨论】:

    标签: python function arguments


    【解决方案1】:

    只需使用星号:

    pro(*math(a,b))
    

    【讨论】:

      【解决方案2】:

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

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

      【讨论】:

        猜你喜欢
        • 2016-05-06
        • 2019-04-23
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2022-01-12
        • 1970-01-01
        • 2020-09-10
        相关资源
        最近更新 更多