First, we define a local variable, which is displayed in the function Why did not define it? Consider the following analysis
Specific code as follows:
# Way: using global strong turn about A =. 1 DEF XXX (): Print (123 ) # global A A = A +. 3 Print (A) # . 4 XXX () Print (A) # . 4 # Second way: A = [. 1 ] DEF XXX (): Print (123 ) A [0] = A [0] +3 Print (A) # [. 4] XXX () Print (A) # [. 4] # third approach class Foo: Pass A = Foo() a.n = 1 def xxx(): print(123) a.n = a.n +3 print(a.n) #4 xxx() print(a.n) #4
First, we define a local variable, which is displayed in the function Why did not define it? Consider the following analysis
Specific code as follows:
# Way: using global strong turn about A =. 1 DEF XXX (): Print (123 ) # global A A = A +. 3 Print (A) # . 4 XXX () Print (A) # . 4 # Second way: A = [. 1 ] DEF XXX (): Print (123 ) A [0] = A [0] +3 Print (A) # [. 4] XXX () Print (A) # [. 4] # third approach class Foo: Pass A = Foo() a.n = 1 def xxx(): print(123) a.n = a.n +3 print(a.n) #4 xxx() print(a.n) #4