diff --git "a/03_Python\345\276\252\347\216\257\350\257\255\345\217\245/09_\345\217\230\351\207\217\344\275\234\347\224\250\345\237\237.py" "b/03_Python\345\276\252\347\216\257\350\257\255\345\217\245/09_\345\217\230\351\207\217\344\275\234\347\224\250\345\237\237.py" index 7114c4a75895baeb8716768c861046979090d59d..66fe5b8f25e4860caa5b6a550fcc34f90208ed78 100644 --- "a/03_Python\345\276\252\347\216\257\350\257\255\345\217\245/09_\345\217\230\351\207\217\344\275\234\347\224\250\345\237\237.py" +++ "b/03_Python\345\276\252\347\216\257\350\257\255\345\217\245/09_\345\217\230\351\207\217\344\275\234\347\224\250\345\237\237.py" @@ -4,4 +4,4 @@ i = 0 for i in range(5): print(i) -print(i) \ No newline at end of file +print(i+1) \ No newline at end of file diff --git "a/04_\345\207\275\346\225\260/10_\345\217\230\351\207\217\347\232\204\344\275\234\347\224\250\345\237\237.py" "b/04_\345\207\275\346\225\260/10_\345\217\230\351\207\217\347\232\204\344\275\234\347\224\250\345\237\237.py" deleted file mode 100644 index 6f7a8353ec299efd04521758b788d46da9d33c14..0000000000000000000000000000000000000000 --- "a/04_\345\207\275\346\225\260/10_\345\217\230\351\207\217\347\232\204\344\275\234\347\224\250\345\237\237.py" +++ /dev/null @@ -1,58 +0,0 @@ -""" -演示在函数使用的时候,定义的变量作用域 -""" - -# 演示局部变量 -# def test_a(): -# num = 100 -# print(num) -# -# -# test_a() -# 出了函数体,局部变量就无法使用了 -# print(num) - -# 演示全局变量 -# num = 200 -# -# def test_a(): -# print(f"test_a: {num}") -# -# def test_b(): -# print(f"test_b: {num}") -# -# test_a() -# test_b() -# print(num) - -# 在函数内修改全局变量 -# num = 200 -# -# def test_a(): -# print(f"test_a: {num}") -# -# def test_b(): -# num = 500 # 局部变量 -# print(f"test_b: {num}") -# -# test_a() -# test_b() -# print(num) - -# global关键字,在函数内声明变量为全局变量 -num = 200 - - -def test_a(): - print(f"test_a: {num}") - - -def test_b(): - global num # 设置内部定义的变量为全局变量 - num = 500 - print(f"test_b: {num}") - - -test_a() -test_b() -print(num) diff --git "a/04_\345\207\275\346\225\260/10_\345\261\200\351\203\250\345\217\230\351\207\217.py" "b/04_\345\207\275\346\225\260/10_\345\261\200\351\203\250\345\217\230\351\207\217.py" new file mode 100644 index 0000000000000000000000000000000000000000..661816ae7fcb474b2d0cfd010f781b816479c9cb --- /dev/null +++ "b/04_\345\207\275\346\225\260/10_\345\261\200\351\203\250\345\217\230\351\207\217.py" @@ -0,0 +1,14 @@ +""" +演示在函数使用的时候,定义的变量作用域 +""" + + +# 演示局部变量 +def test_a(): + num = 100 + print(num) + + +test_a() +# 出了函数体,局部变量就无法使用了 +print(num) diff --git "a/04_\345\207\275\346\225\260/11_\345\205\250\345\261\200\345\217\230\351\207\217.py" "b/04_\345\207\275\346\225\260/11_\345\205\250\345\261\200\345\217\230\351\207\217.py" new file mode 100644 index 0000000000000000000000000000000000000000..ad3e9254b88cf46feec13c2dcc8904e97edf9829 --- /dev/null +++ "b/04_\345\207\275\346\225\260/11_\345\205\250\345\261\200\345\217\230\351\207\217.py" @@ -0,0 +1,18 @@ +""" +演示在函数使用的时候,定义的变量作用域 +""" +# 演示全局变量 +num = 200 + + +def test_a(): + print(f"test_a: {num}") + + +def test_b(): + print(f"test_b: {num}") + + +test_a() +test_b() +print(num) diff --git "a/04_\345\207\275\346\225\260/12_\345\261\200\351\203\250\344\277\256\346\224\271.py" "b/04_\345\207\275\346\225\260/12_\345\261\200\351\203\250\344\277\256\346\224\271.py" new file mode 100644 index 0000000000000000000000000000000000000000..ac91a3efb3daf58c1e1ef087154da02bc9713cd1 --- /dev/null +++ "b/04_\345\207\275\346\225\260/12_\345\261\200\351\203\250\344\277\256\346\224\271.py" @@ -0,0 +1,19 @@ +""" +演示在函数使用的时候,定义的变量作用域 +""" +# 在函数内修改全局变量 +num = 200 + + +def test_a(): + print(f"test_a: {num}") + + +def test_b(): + num = 500 # 局部变量 + print(f"test_b: {num}") + + +test_a() +test_b() +print(num) diff --git "a/04_\345\207\275\346\225\260/13_\345\205\250\345\261\200\344\277\256\346\224\271.py" "b/04_\345\207\275\346\225\260/13_\345\205\250\345\261\200\344\277\256\346\224\271.py" new file mode 100644 index 0000000000000000000000000000000000000000..555bd5f4514e783d6e19d01be0d8f26145077412 --- /dev/null +++ "b/04_\345\207\275\346\225\260/13_\345\205\250\345\261\200\344\277\256\346\224\271.py" @@ -0,0 +1,20 @@ +""" +演示在函数使用的时候,定义的变量作用域 +""" +# global关键字,在函数内声明变量为全局变量 +num = 200 + + +def test_a(): + print(f"test_a: {num}") + + +def test_b(): + global num # 设置内部定义的变量为全局变量 + num = 500 + print(f"test_b: {num}") + + +test_a() +test_b() +print(num) diff --git "a/04_\345\207\275\346\225\260/11_\345\207\275\346\225\260\347\273\274\345\220\210\346\241\210\344\276\213.py" "b/04_\345\207\275\346\225\260/14_\345\207\275\346\225\260\347\273\274\345\220\210\346\241\210\344\276\213.py" similarity index 100% rename from "04_\345\207\275\346\225\260/11_\345\207\275\346\225\260\347\273\274\345\220\210\346\241\210\344\276\213.py" rename to "04_\345\207\275\346\225\260/14_\345\207\275\346\225\260\347\273\274\345\220\210\346\241\210\344\276\213.py"