Variables and types
A variable is a name for a value. Create one with =:
city = "Bulawayo"
population = 650000
population = population + 1000
print(city, population) # Bulawayo 651000
= means "store this value under this name". It does not mean "equals" like in maths: population = population + 1000 reads as "take population, add 1000, and store the result back".
Variable names use lowercase letters and underscores, like first_name. They cannot start with a number or contain spaces.
Types
Every value has a type:
| Value | Type | What it is |
|---|---|---|
"Tendai" |
str |
text (a string) |
21 |
int |
a whole number |
1.75 |
float |
a number with a decimal point |
True / False |
bool |
yes or no |
"21" with quotes is text, not a number. type(value) tells you the type.
print can take several values separated by commas, and puts a space between them.
Your task
- Create
namewith the value"Tendai". - Create
agewith the value21. - On a new line, add 1 to
age. - Print
Tendai is 22using your variables.