Welcome 微信登录
编程资源 图片资源库 蚂蚁家优选 PDF转换器

首页 / 操作系统 / Linux / Python函数嵌套的例子

有关Python函数嵌套的实例,Python中的函数嵌套特性。在Python中函数可以作为参数进行传递,而也可以赋值给其他变量(类似Javascript,或者C/C++中的函数指针);
类似Javascript,Python支持函数嵌套,Javascript嵌套函数的应用模式对Python适用;>>> def multiplier(factor):
... def multiple(number):
... return number * factor
... return multiple
...
>>>
>>> multiplier(3)(3)
9
>>> multiplier(4)(3)与嵌套函数紧密相关的就是闭包特性,例子:>>> def test():
... a = {"name": "wyj"}
... def f():
... return a["name"]
... return f
... www.linuxidc.com
>>> def test():
... a = {"name": "wyj"}
... def f():
... return a["name"]
... return a,f
...
>>> a,f = test()
>>> f()
"wyj"
>>> a["name"] = "ljq"
>>> f()
"ljq"Python解析xml文档实例  http://www.linuxidc.com/Linux/2012-02/54760.htm《Python核心编程 第二版》.(Wesley J. Chun ).[高清PDF中文版] http://www.linuxidc.com/Linux/2013-06/85425.htm《Python开发技术详解》.( 周伟,宗杰).[高清PDF扫描版+随书视频+代码] http://www.linuxidc.com/Linux/2013-11/92693.htmPython脚本获取Linux系统信息 http://www.linuxidc.com/Linux/2013-08/88531.htm在Ubuntu下用Python搭建桌面算法交易研究环境 http://www.linuxidc.com/Linux/2013-11/92534.htmPython 语言的发展简史 http://www.linuxidc.com/Linux/2014-09/107206.htmPython 的详细介绍:请点这里
Python 的下载地址:请点这里本文永久更新链接地址:http://www.linuxidc.com/Linux/2015-01/111125.htm