Every program you have ever used — a game, a calculator, a messaging app — is really just moving values around and doing sums with them. A variable is the program's way of remembering a value and giving it a name, so it can fetch it back later. Master variables and you have the vocabulary that the rest of programming is built from.
Variables: named boxes
Think of a variable as a labelled box in a warehouse. The name is written on the outside; the value is what sits inside. You put a value in using assignment, written with an equals sign that means "becomes":
score = 7
name = "Ava"
score = score + 1
That last line trips people up. It does not mean "score equals score plus one" as a fact — it means "work out the right-hand side, then drop the answer back in the box". So score goes from 7 to 8.
Data types: what kind of value?
Every value has a type, and the type decides what you can do with it. You can add two numbers, but adding two names makes no sense.
| Type | Holds | Example |
|---|---|---|
| Integer | Whole number | 42 |
| Real (float) | Number with a decimal | 3.14 |
| String | Text in quotes | "hello" |
| Boolean | True or False only | True |
| Character | A single symbol | 'q' |
Operators: doing things with values
Arithmetic operators do maths: + - * /. Two special ones matter for exams: DIV gives the whole-number part of a division, and MOD gives the remainder. So 17 DIV 5 is 3 and 17 MOD 5 is 2.
Comparison operators ask a yes/no question and give back a Boolean: == (equal), != (not equal), <, >, <=, >=.
a = 5 → box a holds 5b = 2 → box b holds 2total = a * b → 5 × 2 = 10, so total holds 10rem = 5 MOD 2 → 5 ÷ 2 leaves remainder 1, so rem holds 1check = total > 8 → 10 > 8 is true, so check holds True= (assignment, "put this value in the box") with == (comparison, "are these equal?"). Writing if score = 10 when you mean if score == 10 is one of the most common beginner errors.Give your variables honest names. numberOfLives tells the reader — and future you — exactly what the box holds; x tells them nothing.