在Python3中,如何从列表中提取函数并在参数上调用它? 意思是,实现以下( 不 工作)代码的正确方法是什么:
arr = [int()]
arr[0]("3") # would like to mean: int("3") resulting in the outcome 3
答案 0 :(得分:3)
取消parens
arr = [int]
arr[0]("3")
In [5]: arr = [int]
In [6]: arr[0]("3")
Out[6]: 3
In [7]: type(arr[0]("3"))
Out[7]: builtins.int
In [8]: arr[0]("3") * 10
Out[8]: 30