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.