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

猜你喜欢

转载自www.cnblogs.com/Exesoft-Mike/p/9286397.html
今日推荐