A variable is a named container that holds a value in memory. Assignment binds a name to a value using the assignment operator (e.g., x = 5), replacing any previous value. Variables allow programs to store, retrieve, and update information as computation proceeds. Unlike mathematical variables, programming variables are mutable by default and represent a location in memory, not an unknown.
Trace through short programs by hand, writing down the current value of each variable after each assignment statement. Experimenting in a REPL (read-eval-print loop) gives immediate feedback.
A variable in programming is, at its core, a named location in memory that stores a value. When you write `x = 5`, you are telling the computer: "reserve a spot called x, and put the number 5 there." From that point forward, whenever the program encounters `x`, it looks up what is stored in that spot and uses the value it finds.
Assignment is the act of putting a value into a variable, and it works differently from the equals sign in math. The `=` in programming means "evaluate the right side, then store the result in the left side." This is why `x = x + 1` makes perfect sense in code — it means "take the current value of x, add 1, and store the result back in x." If x was 7, it becomes 8. In mathematics, the equation x = x + 1 is a contradiction, but in programming it is one of the most common operations: incrementing a counter.
One subtle point that trips up beginners is that assignment captures a *value*, not a *connection*. If you write `a = 5` and then `b = a`, b gets the value 5 — a copy of what a held at that moment. If you later change a to 100, b is still 5. Variables do not "watch" each other; they simply hold whatever was last assigned to them. This means the order of statements matters enormously. Swapping the order of two assignments can produce completely different results.
Variables also have types — the kind of data they hold. In some languages you must declare the type explicitly (e.g., `int count = 0`), while in others the language figures out the type from the value you assign (e.g., `count = 0` in Python). Either way, the concept is the same: the variable holds a value, and that value has a type (integer, string, boolean, etc.) that determines what operations you can perform on it. You will explore types in depth when you reach data types, but for now, the key idea is that variables are the fundamental mechanism for storing and manipulating state in a program.