我想将函数存储在一个列表中,然后在程序中从该列表调用这些函数。
这对我有用,但是,我不知道它是否正确:
#example functions, my functions would actually get user input etc.
def func1():
return 2
def func2():
return 3
options = [ func1, func2 ]
#call functions
options[0]()
Run Code Online (Sandbox Code Playgroud)
这是将函数存储在列表中并调用它的正确方法吗?或者有没有其他更好的方法来做到这一点?