Variables & Types

25 min
0/3 practice checks

A variable is a name that refers to a value. You create one with =:

age = 15

Now age holds the integer 15. Python has a few core types:

TypeExampleMeaning
int7whole number
float19.99decimal number
str"Thabo"text (in quotes)
boolTruetrue / false

You never declare the type — Python figures it out from the value. type(x) tells you a value's type.

Code practice

Assign the integer 7 to a variable called age.

python

Runs in your browser. Charts (matplotlib) are not supported — use print-based output.

Code practice

Create price holding the float 19.99 and name holding the string "Zanele".

python

Runs in your browser. Charts (matplotlib) are not supported — use print-based output.

Which line correctly assigns the text Cape Town to a variable city?