19. Local and global variables


# Global and local variable
name = "Parsons 716" # ----- global variable "variable defined function outset
DEF Change ():
" ""
change the global variables, not change
: return:
"" "
name = "Cao Na" # local variables: ---- "internal function defined variable
print (name) # print the local variable name
Print (about locals ()) # print all local variables
Change ()
print (name) # print global variables name
Print (Globals ()) # print global variables
# global variables scope, globally effective, widely available call
# local variable scope, partially valid, in function of the effective
#Variable search order, starting with the local look, not how you look global


name = "Parsons 716" # ----- global variables "function outset variables defined
DEF change ():
" ""
change the global variables, not change
: return:
"" "
, Ltd. Free Join name # - ----------------> I would like to modify global variables
Age = 18
name = "Cao Na"# Local Variables: ---- "internal function defined variable
print (name) # print the local variable name
print (locals ()) # print all local variables
Change ()
Print (name) # prints global variable name
Print (Globals ()) # print global variables

# is not recommended local modification of global variables

Guess you like

Origin www.cnblogs.com/xh716/p/11565929.html