是否可以将带参数的函数传递给 Python 中的另一个函数?
这样说:
def perform(function):
return function()
但是要传递的函数会有如下参数:
action1()
action2(p)
action3(p,r)
最佳答案
你是这个意思吗?
def perform(fun, *args):
fun(*args)
def action1(args):
# something
def action2(args):
# something
perform(action1)
perform(action2, p)
perform(action3, p, r)
https://stackoverflow.com/questions/803616/