Skip to content
dreamcode
dreamcode
Back to map
Variable scope · Lesson 18 of 44
+15 XP on finish
PYTHON BASICS

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.

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.
main.py
PYTHON
real Python, runs in your browser
CONSOLE
- run your code to see output -