码迷,mamicode.com
首页 > 编程语言 > 详细

python装饰器

时间:2018-04-29 23:18:21      阅读:206      评论:0      收藏:0      [点我收藏+]

标签:st3   div   python装饰器   a+b   pre   test   python   func   else   

# def test1(a):
#     def test2(b):
#         return a+b
#     return test2
#
# print(test1(5)(6))

def test3():
    def test4(func):
        def test5(*args,**kwargs):
            return func(*args,**kwargs)
        return test5
    return test4

def test6(a,b):
    def test7(func):
        def test8(*args,**kwargs):
            if a == b:
                return func(*args,**kwargs)
            else:
                print(a,b)
        return test8
    return test7


@test3()
def aaaa(j):
    print(88888+j)
@test6(3,3)
def bbbb(j):
    print(j)
# aaaa(‘7777‘)
bbbb(9999)

带参数装饰器和不带参数装饰器

python装饰器

标签:st3   div   python装饰器   a+b   pre   test   python   func   else   

原文地址:https://www.cnblogs.com/arrow-kejin/p/8972179.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!