python 入坑路--装饰器(语法糖)前戏2

嵌套函数

定义:在一个函数体内,用def 定义另一个函数体,

如下例子是 嵌套函数
def test1():
     print("in the test1")
     def teest2():
           print("in the test2")


以下例子是 函数中引用了其它函数,需要注意区别
def test2():
    print("in the test2")    
    
def test1():
    print("in the test1")
    test2()

再次回顾局部变量及全局变量

如下打印结果 x=4, 局部变量会从内而外去找。

 

posted @ 2017-12-31 23:01  东郭仔  阅读(86)  评论(0)    收藏  举报