【发布时间】:2021-04-04 14:07:46
【问题描述】:
您能否向我解释一下return 对call 和squared_call 的作用?
def mult_by_five(x):
return 5 * x
def call(fn, arg):
"""Call fn on arg"""
return fn(arg)
def squared_call(fn, arg):
"""Call fn on the result of calling fn on arg"""
return fn(fn(arg))
print(
call(mult_by_five, 1),
squared_call(mult_by_five, 1),
sep='\n', # '\n' is the newline character - it starts a new line
)
【问题讨论】:
-
我的理解是在调用函数的时候传递一个操作或者一个变量的值。我要问的是返回函数后的多个括号在 call 和 squared_call 函数中的作用。
-
()调用一个函数。例如。return fn(arg)返回用arg调用fn的返回值。
标签: python-3.x function return-type