Python基础语法(二十一)–闭包之装饰器


装饰器

装饰器的原理就是闭包,调用方式不变


def test(func):
    print('----func----')
    def test2():
        print('----test2这里是扩展功能----')
        func()
    return test2
@test
def test1():
    print('----test1----')

test1()

执行流程图
image

原创文章,作者:6024010,如若转载,请注明出处:https://blog.ytso.com/tech/pnotes/244266.html

(0)
上一篇 2022年4月16日 23:36
下一篇 2022年4月16日 23:36

相关推荐

发表回复

登录后才能评论