码迷,mamicode.com
首页 > 其他好文 > 详细

内嵌函数

时间:2017-01-31 17:41:31      阅读:224      评论:0      收藏:0      [点我收藏+]

标签:error   bsp   not   ast   efi   err   module   mos   无法   

函数的内嵌即在函数内部定义函数,在内部定义的函数所有的一切都在函数内部,外部无法调用,举例如下:

>>> def fun1():
    print("fun1()正在被调用。。。")
    def fun2():
      print("fun2()正在被调用。。。")
    fun2()


>>> fun1()
fun1()正在被调用。。。
fun2()正在被调用。。。
>>> fun2()  #fun2()是在fun1()函数内部创建的,因此在函数外部无法调用
Traceback (most recent call last):
File "<pyshell#37>", line 1, in <module>
fun2()
NameError: name ‘fun2‘ is not defined

内嵌函数

标签:error   bsp   not   ast   efi   err   module   mos   无法   

原文地址:http://www.cnblogs.com/themost/p/6358944.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!