What is the syntax to use the Global Statement?

global <variable name>
#use to modify a global variable from within a function
#tells Python: in this function, <variable name> refers to the global
#version, so don't create a local copy
#example
def myFunction():
    global myVar
    myVar = 123
myVar = 0
myFunction()
print(myVar)

#output
123

 

Advertisements