← All lessons
Programming basics · Lesson 1 of 9

Values and variables

A program is a list of instructions that the computer follows one at a time, top to bottom. This course uses Python, a language that reads a lot like English and is used for everything from websites to science.

The first instruction most people learn is print(). Whatever you put in the brackets is shown on the screen. Text goes in quotes, so Python knows it's text and not an instruction; numbers don't need them.

print("Hello!")
print(42)
print("6 + 1")
print(6 + 1)
Prints
Hello!
42
6 + 1
7

A variable is a name for a value. score = 10 makes a box called score and puts 10 in it. Read = as "becomes", not "equals": the right side is worked out first, then stored under the name on the left. That's why score = score + 5 makes sense: take the old score, add 5, and store the result back.

score = 10
score = score + 5
name = "Ana"
print(name, score)
Prints
Ana 15

Names can use letters, digits and underscores, but can't start with a digit, and capitals matter: Score and score are two different variables. Pick names that say what the value is, like total_price rather than x.

Practice

What does this print?

print("2 + 2")
More info

Quick reference

print(x)Shows x on the screen. Several values with commas between are printed with spaces.
"text"A string (a piece of text). Single quotes work too: 'text'.
name = valueStores the value under the name. The right side is worked out first.
# noteA comment: Python ignores everything after # on the line.

The other computer science courses