Name | Globals |
---|---|
Examples |
# 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. |
Syntax | x = 0 def foo(): global x x = 5 |
Updated on Tue Feb 27 14:07:12 2024.
If you see any errors or have comments, please let us know.
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License