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

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

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 →