Python3 function scope, python3 Function
1 # if True: 2 # x = 3 3 #4 # print (x) 5 #6 # def test (): 7 # a = 10 8 # print () # a does not define 9 10''' 11 Python has four scopes: 12 1.L: local, local, and the variable 13 2.E: enclosing defined in the function, the local scope of the nested parent-level function, including the local scope of the upper-level function of this function, but not the global 14 3.G: global, global variable, variable 15 4. B: built-in defined at the module level. variables in the system fixed module, such as int and bytearray. 16 17 search for variable priority: L> E> G> B18 ''' 19 # sequence example 20 # x = int (5.8) # The built-in21 # a = 1 # global22 # def test1 (): 23 # B = 2 # enclosing24 #25 # def test2 (): 26 # c = 3 # local27 # print (c) 28 # print (B) 29 # print (c) # undefined 30 # test2 () 31 # test1 () 32 33 # count = 1034 # def outer (): 35 # print (count) 36 # count + = 1 # global variables cannot be modified unless you create variable 37 # outer ()