2024-04-26 04:28:07 发布
网友
有没有一种方法可以在python中实现这样的功能?在
another_function( function(x) {return 2*x} )
def another_function( function=lambda x: 2*x ): print(function(10)) #an example
我不确定您发布的示例代码会发生什么,但是如果您调用another_function它将调用function(10)并打印20。在
another_function
function(10)
更重要的是,不能调用another_function(7)和get 14,因为7将被分配给function和{}TypeError:“int”对象不可调用`。在
another_function(7)
14
7
function
是的:
another_function( lambda x: 2*x )
需要说明的是:这是在调用another_function时发生的,而不是在定义它时发生的。在
我不确定您发布的示例代码会发生什么,但是如果您调用
another_function
它将调用function(10)
并打印20。在更重要的是,不能调用}TypeError:“int”对象不可调用`。在
another_function(7)
和get14
,因为7
将被分配给function
和{是的:
需要说明的是:这是在调用
another_function
时发生的,而不是在定义它时发生的。在相关问题 更多 >
编程相关推荐