Appendix D. Variable Scope
The rule of variable scope in Python is defined simply: a variable created inside a function exists only inside that function. This means that a variable created inside setup() can be used only within setup(), and likewise, a variable declared inside draw() can be used only inside draw(). The exception to this rule is a variable declared outside of setup() and draw(). These variables can be used in both setup() and draw() (or inside any other function that you create). We call these variables global variables, because they can be used anywhere within the program. We call a variable that is used only within a single function a local variable. Following are a couple of code examples that further explain the concept. ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access