装饰器练习——Python

Demo1:

def add():
    return 1+1

def sub():
    return 2-1

print(add())
print(sub())

Demo2:

def add():
    return 1+1

def sub():
    return 2-1

print(add())
print(sub())

Demo3:

def add():
    return 1+1

def sub():
    return 2-1

print(add())
print(sub())

Demo4:

def printLine(func):
    def f():
        print("-----------")
        return func()
    return f

@printLine
def add():
    return 1+1

@printLine
def sub():
    return 2-1


print(add())
print(sub())

 

posted on 2018-07-09 22:11  格码拓普  阅读(138)  评论(0编辑  收藏  举报