Skip to content

Variables

A variable is a box with a name written on it. You put information inside, then call it back later by its name:

Inputs (for input())

One value per line — read in order by input().

Output
 

name = "Aysel" reads like this: “make a box called name, and put the text Aysel inside it”. Here = doesn’t mean “equals” — it means “assign”.

The easiest way to use a variable inside a sentence is an f-string. Write f before the quote, and wrap the variable in curly braces:

Inputs (for input())

One value per line — read in order by input().

Output
 

Python replaces whatever is inside the curly braces {} with the variable’s value. It looks like magic, but it’s real technology. ✨

That’s exactly where the name comes from — variable (something that can vary):

Inputs (for input())

One value per line — read in order by input().

Output
 

score = score + 10 looks odd, but the logic is simple: “take the old value of the score box, add 10, and put the result back in the box”. The score counter in computer games works exactly like this. 🎮

  • No spaces: my name ❌ → my_name ✅ (use _ instead of a space)
  • Can’t start with a number: 1score ❌ → score1
  • Uppercase and lowercase matter: Name and name are two different boxes!
Mission

Intro card

+10 XP

Make the variables name and age (with your own info) and print both of them in one sentence using a single f-string.

Inputs (for input())

One value per line — read in order by input().

Output
 
Mission

Age calculator

+15 XP

Put your own birth year into the birth_year variable, and have the program calculate and print how old you are (roughly).

Inputs (for input())

One value per line — read in order by input().

Output
 
Mission

Score counter

+15 XP

Build a game counter: score starts at zero, grows three times with score = score + 10, and is shown at the end with print.

Inputs (for input())

One value per line — read in order by input().

Output
 

Next lesson: the program will talk with you — we’ll learn to get information from the user with input(). Continue →