python核心编程-函数-内嵌函数

来源:互联网 发布:2017年国产动漫数据 编辑:程序博客网 时间:2024/05/16 04:52
#!/usr/bin/env python# -*- coding: UTF-8 -*- def foo():    def bar():  #bar只在foo函数的作用域内        print 'bar() called'    print 'foo() called'    bar()if __name__ == '__main__':    foo()    bar()

输出:

D:\Python27\test>func4.pyfoo() calledbar() calledTraceback (most recent call last):  File "D:\Python27\test\func4.py", line 13, in <module>    bar()NameError: name 'bar' is not definedD:\Python27\test>
0 0
原创粉丝点击