函数参数定义中的类型注释:我想在 python 中实现一个高阶函数,为此我想要显式参数类型。有没有办法显示“函数”类型?
def high_order_math(a: Float, b: Float, func: function):
return func(a,b)
Run Code Online (Sandbox Code Playgroud)
这是一些发现,感谢所有分享您的知识的人
def high_order_math(a: float, b: float, func: Callable[[float, float], float]) -> float:
return func(a, b)
high_order_math(1,2,3)
Run Code Online (Sandbox Code Playgroud)
回溯(最近一次调用最后一次):
文件“”,第 1 行,在
文件“”,第 2 行,在 high_order_math
类型错误:“int”对象不可调用