00 装饰器引入

day13 .装饰器

v = 1
v = 2 
# ########################
def func():
    pass 
v = 10
v = func

# ##########################
def base():
    print(1)

def bar():
    print(2)

bar = base
bar()
def func():
    def inner():
        pass
    return inner 

v = func()
print(v) # inner函数
# #########################################
def func(arg):
    def inner():
        print(arg)
    return inner 

v1 = func(1)
v2 = func(2)

# #########################################
def func(arg):
    def inner():
        arg()
    return inner

def f1():
    print(123)

v1 = func(f1)
v1()
# ###########################################
def func(arg):
    def inner():
        arg()
    return inner

def f1():
    print(123)
    return 666

v1 = func(f1)
result = v1() # 执行inner函数 / f1含函数 -> 打印123 ,返回666 inner函数里面因没有return,所以f1的中的返回值没有意义
print(result) # None
# ###########################################
def func(arg):
    def inner():
        return arg()  #返回 666
    return inner

def f1():
    print(123)
    return 666

v1 = func(f1)
result = v1() # 执行inner函数 / f1含函数 -> 123
print(result) # 666

def func():
    print(1)
    
v1 = func
func = 666
posted @ 2024-09-26 06:17  jhchena  阅读(4)  评论(0编辑  收藏  举报