代码:
闭包
#coding=utf-8
#闭包:对外部作用域的变量进行引用的内部函数
"""
闭包的条件:
一个闭包至少要有两层嵌套关系
内嵌的函数要引用外部函数的变量
闭包必须返回嵌套函数
"""
def bibao_one():
Jay = "哎哟不错哦"
def bibao_two():
print(Jay)
return bibao_two()
#执行闭包
execute = bibao_one()
execute
执行结果
装饰器
"""
装饰器:
在不更改原有代码的基础之上附加功能
"""
def three(hello):
def four():
print("我爱重庆")
hello()
print("我爱四川")
return four()
#执行装饰器
@three
def yaya():
print("我爱深圳")
yaya
执行结果