Arithmetic operators perform mathematical calculations. Python supports all standard maths operations:
| Operator | Name | Example | Result |
|---|---|---|---|
+ | Addition | 7 + 3 | 10 |
- | Subtraction | 7 - 3 | 4 |
* | Multiplication | 7 * 3 | 21 |
/ | Division (float result) | 7 / 2 | 3.5 |
// | Integer division (DIV) | 7 // 2 | 3 |
% | Modulus / remainder (MOD) | 7 % 2 | 1 |
** | Exponentiation (power) | 2 ** 8 | 256 |
DIV (//): Integer division — divides and discards the remainder (floor division)
MOD (%): Gives the remainder after division. Very useful for:
n % 2 == 0n % 5 == 0n % 10 gives the units digitPython follows BIDMAS/BODMAS order:
() — highest priority**/ and Multiplication * (equal priority, left to right)+ and Subtraction - (lowest)Comparison operators compare two values and return a Boolean (True or False). Used in if statements and while conditions:
| Operator | Meaning | Example | Result |
|---|---|---|---|
== | Equal to | 5 == 5 | True |
!= | Not equal to | 5 != 3 | True |
> | Greater than | 7 > 3 | True |
< | Less than | 3 < 7 | True |
>= | Greater than or equal to | 5 >= 5 | True |
<= | Less than or equal to | 4 <= 3 | False |
Shorthand operators for updating variables:
| Operator | Example | Equivalent to |
|---|---|---|
+= | x += 5 | x = x + 5 |
-= | x -= 3 | x = x - 3 |
*= | x *= 2 | x = x * 2 |
//= | x //= 2 | x = x // 2 |
= (assignment) instead of == (equality check) in a condition7 / 2 = 3 — in Python 3, / always gives a float (3.5). Use // for integer division2 + 3 * 4 = 14, not 20DIV and MOD as MOD, not // or %8 Edexcel-style questions · instantly marked
| Term | Definition |
|---|
Timed exam-style test — 10 minutes.