python--闭包

2018-07-22  本文已影响0人  3e0a50393df8

内部函数对外部函数作用域里变量的引用(非全局变量),则称内部函数为闭包。

 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))
上一篇 下一篇

猜你喜欢

热点阅读