Arithmetic
| Operator | Meaning | Example | Result |
|---|---|---|---|
+ | add | 7 + 2 | 9 |
- | subtract | 7 - 2 | 5 |
* | multiply | 7 * 2 | 14 |
/ | divide (always a decimal) | 7 / 2 | 3.5 |
// | divide, drop the remainder | 7 // 2 | 3 |
% | remainder | 7 % 2 | 1 |
** | power | 7 ** 2 | 49 |
print(7 + 2)
print(7 / 2)
print(7 // 2)
print(7 % 2)
print(7 ** 2)
Output:
9
3.5
3
1
49
A real example: you buy 3 notebooks at Rs 45 each and pay with a Rs 200 note.
price = 45
count = 3
total = price * count
change = 200 - total
print("Total:", total)
print("Change:", change)
Output:
Total: 135
Change: 65
Order of operations
Python follows the usual maths order: brackets, then powers, then multiply and divide, then add and subtract. Use brackets to be clear.
print(2 + 3 * 4)
print((2 + 3) * 4)
Output:
14
20
Comparing values
Comparisons give True or False: == (equal), != (not equal), <, >, <=, >=. Notice that == compares, while a single = stores.
marks = 62
print(marks >= 40)
print(marks == 100)
print(marks != 62)
Output:
True
False
False
Combining conditions
and needs both sides to be true, or needs at least one, and not flips the answer.
age = 17
has_card = True
print(age >= 16 and has_card)
print(age < 10 or has_card)
print(not has_card)
Output:
True
True
False
Try it yourself
- Work out the area of a rectangle 12 cm by 7 cm with variables.
- Find the remainder when 2026 is divided by 7.
- Check whether a number is even using
%.
Next lesson: making your program decide with if.

Comments
Loading comments…