Python中 def xxx(func)学习

Python中 def xxx(func)学习

看项目发现的,函数内部使用func(),网上了解一下,这里用其他人问的一个例子。

def identity_decorator(func):
    def wrapper():
        func()
    return wrapper
  • func是给函数identity_decorator()的参数。
  • 表达式func()表示“调用分配给变量func的函数”
  • decorator将另一个函数作为参数,并返回一个新函数(定义为wrapper),该函数在运行时执行给定的函数func。

装饰器的内容有空再做补充。

posted @ 2021-10-21 18:29  Zhang_777  阅读(305)  评论(0编辑  收藏  举报