装饰器练习——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())