GCSE Computer Science

Python operators โ€” GCSE Computer Science

Arithmetic operators

print(17 / 5)    # 3.4
print(17 // 5)   # 3
print(17 % 5)    # 2
print(2 ** 3)    # 8

// and % are the two that catch people out. 17 // 5 asks "how many whole times does 5 go into 17?" โ€” 3. 17 % 5 asks "what's left over?" โ€” 2. Together, they always agree: (17 // 5) * 5 + (17 % 5) comes back to 17.

Comparison operators

== equal to, != not equal to, < less than, > greater than, <= less than or equal to, >= greater than or equal to. Every comparison operator evaluates to True or False.

Logical operators

age = 17
has_id = True

if age >= 18 and has_id:
    print("Entry allowed")

and requires both conditions to be true. or requires at least one. not reverses a boolean. Combining comparison operators with logical operators, as above, is one of the most common patterns in GCSE selection questions.

Assignment operators

total = 0
total += 5    # same as total = total + 5
print(total)  # 5

= assigns a value. += adds to the existing value and reassigns it in one step; -= does the same with subtraction. They're shorthand โ€” total += 5 and total = total + 5 do exactly the same thing.

// and % in pseudocode: DIV and MOD

GCSE pseudocode doesn't use // and % โ€” it uses DIV and MOD instead, and they do exactly the same jobs. 17 DIV 5 is 3. 17 MOD 5 is 2. The mapping between Python and pseudocode here is explicitly tested โ€” know that DIV means // and MOD means %, in both directions.

Operator precedence

Python evaluates ** first, then * / // %, then + -, and comparisons after all of that. Brackets override everything and force a specific order โ€” when in doubt, use them.

result = 2 + 3 * 4
print(result)   # 14, not 20 - multiplication happens before addition
Common exam mistake

Using = instead of == in a condition. = assigns a value; == compares two values. In Python this is actually a syntax error โ€” you can't assign inside a condition โ€” but students write it that way on paper, and it reads as a logic error to an examiner marking pseudocode or a flowchart. Either way, it loses marks.

What examiners actually test

Operator questions usually ask you to state the output of an expression using //, %, or a combination of comparison and logical operators, or to convert between Python's // / % and pseudocode's DIV / MOD. Precedence questions โ€” where the order operations happen in changes the answer โ€” come up often enough to be worth memorising the order deliberately, not guessing.

Python Coach covers hundreds of challenges taking students from their first print statement to advanced Python โ€” with progress tracking for every student.

Start your school's free trial →