Computer memory is where data is stored during program execution. Variables are named locations in memory that hold values. Understanding this model helps explain how data persists and changes as a program runs.
Draw memory diagrams showing variables as boxes with names and values. Watch how values change as assignments execute.
Before you can understand how programs work, you need a mental model of where data actually lives while a program runs. A computer's memory (RAM) is a vast array of numbered slots, each capable of holding a small piece of data. Think of it as a giant wall of post office boxes: each box has a unique address (a number), and each box holds some contents. When your program stores the number 42, that value is placed into one of these slots, and the computer remembers which slot it used.
A variable is the programmer's way of giving a meaningful name to one of those memory slots. Instead of saying "put 42 into slot number 7,293,401," you write `score = 42`, and the computer handles the address mapping for you. The name `score` is a label that refers to a specific location in memory. When you later write `print(score)`, the computer looks up where `score` lives, retrieves the value stored there (42), and displays it. This name-to-location mapping is what makes programs readable — humans think in names like `temperature` and `username`, not in raw memory addresses.
The key insight is that variables are mutable — the value in a memory location can change. When you write `score = 42` followed by `score = 85`, you haven't created two variables. You've changed the contents of the same memory location from 42 to 85. The old value is simply overwritten and lost. This is why the order of statements matters: `score = 42` then `score = score + 10` produces 52, but reversing them would fail (or produce a different result) because `score` wouldn't have a value yet. Understanding that assignment replaces the current value — rather than somehow remembering both — prevents a common class of confusion when programs update variables in loops or accumulate totals.
Memory is finite. A typical computer has billions of these storage slots, which sounds like a lot, but programs that process images, videos, or large datasets can consume memory quickly. For now, the practical takeaway is that every piece of data your program uses — every number, every piece of text, every true/false flag — occupies space in memory, and variables are how you name and access those spaces. As you progress to data types, you'll see that different kinds of data require different amounts of memory, which is one reason types exist.
This is a foundational topic with no prerequisites.
No prerequisites — this is a starting point.