小编Sam*_*ira的帖子

Python中有没有办法确保我的函数的一个参数是另一个函数?

函数参数定义中的类型注释:我想在 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”对象不可调用

python python-3.x

5
推荐指数
1
解决办法
226
查看次数

标签 统计

python ×1

python-3.x ×1