The Six Comparison Operators

print(5 == 5)   # True
print(5 != 3)   # True
print(5 < 3)    # False

Chained Comparisons

x = 7
if 0 < x < 10:
    print("single digit")

Strings Are Compared Alphabetically

"apple" < "banana"   # True
"Z" < "a"            # True (uppercase < lowercase in ASCII)

== vs is

== checks value equality. is checks identity (same object in memory). For HKDSE, always use == unless comparing to None:

if value is None:
    print("missing")

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 →