# _*_ coding: utf-8 _*_ # global: 在局部声明变量是全局变量 # x=1 # def func(): # global x # x=2 # # func() # print(x) #2 # nonlocal:在局部声明变量是外层函数的变量 # # x=333 # def f1(): # x=222 # def f2(): # x=111 # # x = 0 # def f3(): # nonlocal x # x=0 # f3() # print('f2内部的x: ',x) # f2() # print('这是f1内部的x: ',x)#现在当前层找所以 x=222 # # f1() # print(x)