PYTHON BASICSChapter 4 · Functions
Local and global variables
Variables created inside a function are local to that function. They cannot be seen or used outside. Variables created outside functions are global and can be read anywhere.
Worked example
How it reads
- sky = "neon" is a global variable accessible inside and outside paint()
- cloud = "puffy" is a local variable only accessible inside paint()

Cloud tip: Keeping variables local helps prevent errors, because different functions won't accidentally overwrite each other's data.


