闭包,装饰器,property

其实装饰器它就是一个闭包。装饰器实现的是,返回一个内嵌的函数以及函数所需要的外部变量,

什么是闭包?(https://www.bilibili.com/video/av49346682

如果一个函数定义在另一个函数的作用域内,并且引用了外层函数的变量,则该函数称为闭包。

闭包例子:

def outer(name):
def inner():
print(name)
return inner # 返回一个inner函数对象,其实不加括号的函数inner就是一个地址

res = outer('python')
res()



def

猜你喜欢

转载自www.cnblogs.com/wisir/p/12424072.html
今日推荐