1.global is called a keyword in python, not a command
The role of 2.global is to refer to global variables to local scopes
3. If there is not a variable A in the global variable and a statement such as Globa A is written in the function, then a variable a is created in the global variable
4. code example:
########################################################################
a=10
def fun ():
Global A
A = 20
Fun ()
Print (a)
Summary: A general example of referencing global variables in a function, that is, a local scope
#########################################################################
def fun ():
Global A
A = 20
Fun ()
Print (a)
Summary: This code because there is no global variable A, and the function refers to the variable A, the subsequent execution of the SUM function, so print out the global variable A
############################################################################
"Key Notes"
When will the global general be used? This is useful when you want to change global variables in a local scope.
--------------------------------------------------------------------------------------------------------------- ------------------
a=10
def fun ():
Global A
A = 20
A=a+30
Fun ()
Print (a)
Summary: This code will end up typing 40, because in the local scope has changed the global variable a value, the global variable in a is not the previous 10, now is the modified 40
Python References global variables