视频中使用到的代码
# 2.如何在一个函数内部修改全局变量# 通过使用global对全局变量进行修改。# n=0# def foo():# global n# n=100# foo() # print(n)x = 0def outer(): x = 1 def inner(): nonlocal x x = 2 print("inner:", x) inner() print("outer:", x) outer()print("global:", x)# x = 0# def outer():# x = 1# def inner():# nonlocal x# x = 2# print("inner:", x) # inner()# print("outer:", x) # outer()# print("global:", x)