创新互联Python教程:python闭包的特点
1、在外部函数中定义内部函数,内部函数包含访问外部函数。即使外部函数的生命周期结束后,内部函数仍然可以访问外部函数变量。

2、外部函数的返回值是内部函数本身。
实例
def outer():
cheer = 'hello '
def inner(name):
return cheer + name
return inner
if __name__ == "__main__":
#输出hello kevin
print(outer()('kevin'))以上就是python闭包的特点,希望对大家有所帮助。更多Python学习指路:创新互联python教程
网页题目:创新互联Python教程:python闭包的特点
URL地址:http://www.jxjierui.cn/article/djcpdeg.html


咨询
建站咨询
