内部函数对外部函数作用域里变量的引用(非全局变量),则称内部函数为闭包。
1 def test(a,b):
2 def test1(x):
3 return a*x+b
4 return test1
5 t = test(2,3)
6 print(t(5))
内部函数对外部函数作用域里变量的引用(非全局变量),则称内部函数为闭包。
1 def test(a,b):
2 def test1(x):
3 return a*x+b
4 return test1
5 t = test(2,3)
6 print(t(5))
本文标题:python--闭包
本文链接:https://www.haomeiwen.com/subject/nkalmftx.html
网友评论