Python3:从列表中提取函数并让它在参数上运行

时间:2014-08-19 13:30:17

标签: python list function

在Python3中,如何从列表中提取函数并在参数上调用它? 意思是,实现以下( 工作)代码的正确方法是什么:

arr = [int()]
arr[0]("3") # would like to mean: int("3") resulting in the outcome 3

1 个答案:

答案 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