What Is a Variable?
A variable is a name that points to a value in memory. Python figures out the type automatically — you do not need to declare it.
name = "Chan" # str age = 17 # int height = 1.72 # float is_student = True # bool nothing = None # NoneType
The Five Core Types
- int — whole numbers like
42,-3. - float — decimals like
3.14,-0.5. - str — text in quotes,
"Hello"or'Hi'. - bool —
TrueorFalse(capital letters). - NoneType —
None, meaning "no value".
Checking the Type
print(type(age)) # <class 'int'> print(isinstance(age, int)) # True
Converting Between Types
x = int("42") # str → int
y = float("3.14") # str → float
z = str(100) # int → str
b = bool(0) # False
Naming Rules
- Start with a letter or underscore.
- Cannot start with a digit.
- No spaces or hyphens — use snake_case.
- Cannot be a reserved word (e.g.
class,for).
Practise this on PyForm — free
PyForm runs Python in your browser with an AI tutor trained for HKDSE. No install, no credit card.
Open PyForm →