Python闭包的使用
1、这里使用Ubuntu系统做一个小例子演示,登录Ubuntu系统,打开终端,输入python3进入python交互环境

3、在交互环境继续执行代码如下:>>> def test():... print ('test')...>>> test<function test at 0x7f42187dfea0>>>> f = test f就是test函数的地址,f()同样可以调用这个函数>>> f()test这有点类似c++语言函数指针的概念,但是使用要简单很多

5、在‘test.py’文件写代码如下:1 def test(number1): 2 print ('testin start') 3 def testin(): 4 print ('testin start') 5 print (number1+1) 6 7 return testin 8 test(100)

7、重新打开‘test.py’更改代码如下:def test(number1): print ('test start') def testin(): print ('testin start') print (number1+1) return testina = test(100)print (a())

声明:本网站引用、摘录或转载内容仅供网站访问者交流或参考,不代表本站立场,如存在版权或非法内容,请联系站长删除,联系邮箱:site.kefu@qq.com。
阅读量:48
阅读量:62
阅读量:50
阅读量:88
阅读量:27