Why Python? Why Now?

Python is the programming language of the decade. It powers Instagram, YouTube, Netflix, and most modern AI systems including ChatGPT. In Hong Kong, Python skills are increasingly valued in finance (algorithmic trading), logistics (data analysis), and technology companies.

For HKDSE students, Python is the required programming language for ICT Paper 1. But its value extends far beyond the exam — Python is the most in-demand programming language in Hong Kong's job market.

Try as you read: Open PyForm in another tab and run every code example in this guide as you read it. Learning by doing is 10x more effective than passive reading.

Your First Python Program

Every programmer's first program prints "Hello, World!" on the screen. In Python, it's one line:

print("Hello, World!")

Now let's make it more local:

print("你好,香港!")
print("Let's learn Python!")
print("HKDSE ICT, here we come!")

Run this in PyForm. You should see three lines of output. Congratulations — you're a programmer.

Variables: Storing Information

A variable is like a labelled box that stores a piece of information. In Python, you create a variable by choosing a name and assigning a value with =.

# Student information
student_name = "Chan Siu Ming"
student_age = 17
student_class = "5A"
exam_score = 85.5

print(student_name)    # Chan Siu Ming
print(student_age)     # 17
print(exam_score)      # 85.5

Variable names follow rules:

Data Types: The Four You Need

Python has four basic data types you must know for HKDSE:

# Integer — whole numbers
octopus_balance = 150
num_students = 42

# Float — decimal numbers
mtr_fare = 12.50
bmi = 22.8

# String — text (use quotes)
school_name = "Victoria Secondary School"
district = "Kowloon Tong"

# Boolean — True or False
is_student = True
has_student_id = False

# Check the type of any variable:
print(type(octopus_balance))  # int
print(type(mtr_fare))         # float
print(type(school_name))      # str
print(type(is_student))       # bool

Input: Getting Data from Users

Programs become interactive when they accept input from users. Python's input() function reads a line of text:

name = input("Enter your name: ")
print("Hello,", name)

Important: input() always returns a string. To do maths with the input, convert it first:

age_text = input("Enter your age: ")
age = int(age_text)           # Convert to integer
next_year = age + 1
print(f"Next year you'll be {next_year}")

Conditions: Making Decisions

Real programs make decisions. Python uses if, elif, and else:

score = int(input("Enter your DSE score: "))

if score >= 80:
    print("Grade A — Excellent!")
elif score >= 65:
    print("Grade B — Good work!")
elif score >= 50:
    print("Grade C — Pass")
elif score >= 35:
    print("Grade D — Borderline")
else:
    print("Grade F — Need improvement")

# Indentation is crucial in Python!
# Everything inside an if block must be indented

Loops: Repeating Actions

Loops let you repeat actions without writing the same code over and over:

# For loop — repeat a set number of times
for i in range(1, 11):  # 1 to 10
    print(f"{i} x 3 = {i * 3}")

# While loop — repeat while a condition is true
balance = 100
fare = 15

while balance >= fare:
    balance -= fare
    print(f"Fare paid. Balance: ${balance}")

Your First Complete Program

Let's combine everything into a program that calculates your Octopus card usage:

# Octopus Card Calculator
print("=== Octopus Card Calculator ===")

balance = float(input("Enter starting balance (HKD): "))
trips = int(input("How many trips today? "))

total_spent = 0

for i in range(trips):
    fare = float(input(f"Trip {i+1} fare: $"))
    if fare > balance:
        print("Insufficient balance!")
        break
    balance -= fare
    total_spent += fare
    print(f"Paid ${fare:.2f}. Remaining: ${balance:.2f}")

print(f"\nSummary: Spent ${total_spent:.2f}, Balance: ${balance:.2f}")

Practice Python in Your Browser

Run all these examples in PyForm — no installation, no setup. Just open and code.

Open PyForm Free →