【问题标题】:python : syntax for accessing the return result of the non static functionpython:访问非静态函数返回结果的语法
【发布时间】:2017-10-29 16:00:14
【问题描述】:

在python中不再次调用该函数的情况下,访问作为参数传入另一个函数的非静态函数的返回结果的语法是什么?

例子:

def func(a,b):
    return (a+b)
def compute(func)
    # what to write here so as to access return value here without calling func

有可能吗??

【问题讨论】:

  • 你想得到函数的结果作为参数传递而不调用它?干什么用的?
  • 不调用就没有返回值。更重要的是,返回值取决于参数(你似乎没有)。这里真正的问题是:为什么要避免调用该函数?您要解决的实际问题是什么?

标签: python function arguments


【解决方案1】:

不调用函数就无法获取返回值。此外,您的函数需要参数,因此您需要调用该函数才能获得确定的返回值。

您可能还需要更改参数名称,因为“func”是您的函数和参数的名称。

这样称呼它:

def compute(newParamName):
    func(num1, num2)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-09-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-11-18
    • 1970-01-01
    • 2014-04-26
    相关资源
    最近更新 更多