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
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 = valueCode
age = 18
print(age)Output
18
Why it works
- The first line creates age and stores 18.
- 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.