Module 3 of 15 · Step 1 of 10

Variables

A variable gives a value a name. This lets a program reuse information and update it without rewriting every instruction.

By the end of this lesson, you can:
  • Assign and print values
  • Update an existing variable
  • Choose valid, readable names
  • Use names consistently
Variables lesson progress0%

Course progress: 0% · 0 of 10 steps completed in this module

Learn · Give a value a name
Concept 1 of 4

Give a value a name

Assignment uses =. Read age = 18 as 'store 18 under the name age.' Later, writing age reads that stored number; writing "age" means the literal word.

Pattern
name = value
Code
age = 18
print(age)
Output
18

Why it works

  1. The first line creates age and stores 18.
  2. The second line reads age and displays its current value.

Common mistake

Not this
print("age")
Try this
print(age)

Quotes display the word age instead of the stored value.