Index Ai Academy
Phase 0 · ToolsPython core

Variables

About 20 minLooking ahead: some prerequisites aren't done yet

Why this matters

Every AI program moves named values around. The prompt you send. The API key that proves who you are. The model's reply. The score you give that reply. Variables are how code holds on to those values from one step to the next. Get comfortable here, and the code in every later lesson reads like a list of plain instructions.

  • Store a value under a name and use it later
  • Predict what a variable holds after it's reassigned
  • Tell text, whole numbers and decimals apart with type()
  • Pick names Python accepts and people can read

A name for a value

Think of a sticky label you put on a box. The label is the name, and whatever is in the box is the value. A variable is exactly that: a name that refers to a value. You create one with a single equals sign:

campaign = "Spring Sale"
budget = 5000
print(campaign)
print(budget)

Read budget = 5000 as "store 5000 under the name budget", not as "budget equals 5000". The = sign is an instruction, not a statement of fact. Python works out the value on the right first. Then it sticks the name on the left onto it.

Once a name exists, you can use it anywhere you'd use the value itself. That includes a calculation that creates another variable:

budget = 5000
spent = 1200
remaining = budget - spent
print(remaining)