# We create the global x by declaring it outside of a function. 
x = 0

def keyPressed():
    # We want to modify the global x. 
    global x 
    x = x + 1

def draw():
    # We wish to read the global x.
    ellipse(x, height / 2, 10, 10)
Description Global variables are declared outside functions and are readable throughout the program. If you wish to modify or create a global variable from within a function, you must use the global Python statement.
	x = 0

	def foo():
	    global x
	    x = 5 
Updated on Fri Aug 16 21:51:57 2019.
Creative Commons License