Variable scope, local and global:
= 20 the X- # the X-define global variables from the beginning to the end of the program, has been available visible. DEF foo (): Print (X) foo () DEF bar (): X = 50 # where X is a local variable, global variable obscured, does not affect the values of global variables. Print (X) bar () # X -> 50 Print (X) # X -> 20 is DEF AAA (): Global X # global variable is used in the local X = 100 # global variable X reassign 100 Print (X) # X -> 100 AAA () Print (X) # X -> 100
Output results:
20 50 20 100 100