Skip to content

Lesson 2 · variables and numbers

Variables, little jars

  1. 1. Story
  2. 2. Guess
  3. 3. Your turn

KaiThree cups of latte, four dollars each. I keep forgetting the numbers.

SitaraPut each number in a named jar. Python remembers it for you.

Mochi(sits inside an empty jar, which is not what Sitara meant)

A variable is a named jar that holds a value.

  1. 1. name = value puts a value in the jar
  2. 2. Numbers have no quotes
  3. 3. Later, use the name and Python looks inside the jar
cafe.py

Try: Change cups to 5, then run it again.

Read · about 1 minute

The basics, in plain words

A variable is a named jar that holds a value.

latte_price = 4
cups = 3
print(latte_price * cups)
  • name = value puts a value in the jar
  • Numbers have no quotes
  • Later, use the name and Python looks inside the jar
variable
A name that holds a value, like a labelled jar: cups = 3.
=
Puts the value on the right into the name on the left. It is not “equals” in maths.

Common slip: Names can’t have spaces. Write latte_price, not latte price.

Read all twelve Python basics with Sitara →
Next · lesson 3 · about 10 minutesAdding up a billYou will learn maths and f-strings.Next lesson →