What is a Variable?
In Python, a variable is a named location in memory that stores a piece of data. Think of it as a labelled box โ you give the box a name, put something inside, and can retrieve or update that value at any point in your program.
Real-world analogy
score = 10 at the top. Later, she erases 10 and writes 20. The label "score" stays fixed โ only the value inside changes. That is exactly what a Python variable does.Name
Every variable has a unique identifier (e.g. score, player_name, is_alive) that you choose when you create it.
Value
The data stored inside โ a number, text, True/False, or a more complex object.
Mutable
Unlike a fixed constant, a variable's value can be updated as many times as needed while the program runs.
No declaration needed
Python is dynamically typed. You don't need to say 'this is an integer' โ Python figures it out automatically.
Key vocabulary
- Assignment โ storing a value in a variable using the = operator.
- Data type โ the kind of data stored (int, float, str, bool).
- Dynamic typing โ Python infers the type automatically.
- Re-assignment โ giving a variable a new value (can even change its type!).
๐งช Compact Variable Playground
Run the script below and watch how score updates from 10 to 20 in the Variable Inspector:
๐งช Compact Variable Playground
Ready to run
No variables yet.
Run your Python code to see them appear here live!
No variables yet.
Run your Python code to see them appear here live!