Python · Stage 1 · Storing Information · Lesson 7 of 50

Variables: Labeled Boxes

Store one value under a memorable name and use it again later.

This instruction creates a variable named name and stores text in it:

name = "Maya"
Line-by-line explanation
  1. name is the label we chose.
  2. = means “store the value on the right under the name on the left”.
  3. "Maya" is the value being stored.

Use the name without quote marks to read the stored value:

print(name)
Line-by-line explanation
  1. print displays a value.
  2. name has no quotes, so Python looks inside the variable.
  3. The output is Maya.

Assigning a new value is like replacing what is inside the same labeled box:

name = "Noah"
Line-by-line explanation
  1. name is the same label.
  2. = performs another assignment.
  3. "Noah" replaces the earlier value.

Tiny Practice: Make a Labeled Box

Store your favorite color in color, then display it.

Starter template

color = "CHANGE ME"
print(color)
Line-by-line explanation
  1. The first line stores text under color.
  2. The second line displays the stored value.
Hint
  1. Replace only CHANGE ME.
  2. Keep quotes around the color.
  3. Do not quote color on the second line.
Show Solution
color = "blue"
print(color)
Line-by-line explanation
  1. The first line stores blue.
  2. The second line reads color.
  3. The output is blue.