Python Variables and Data Types Explained for Beginners (int, float, str, bool)
P2.4 Python Arithmetic Operators with Examples
Why. Totals, averages, discounts and percentages are the daily maths of data work.
What. Python has these maths operators:
| Operator | Meaning | Example | Result |
|---|---|---|---|
| + | add | 10 + 3 | 13 |
| - | subtract | 10 - 3 | 7 |
| * | multiply | 10 * 3 | 30 |
| / | divide (always float) | 10 / 3 | 3.333... |
| // | whole-number divide | 10 // 3 | 3 |
| % | remainder | 10 % 3 | 1 |
| ** | power | 10 ** 3 | 1000 |
How to read this table: each row is one operator. Example shows it with 10 and 3; Result is what Python gives.
How.
Work out a discount
- Store the price.
- Store the discount as a decimal (10% = 0.10).
- Multiply to get the discount amount.
- Subtract it from the price.
- Round the answer with
round(value, 2).
Worked example A — A simple discount.
Step 1 — What we do. A store in New York sells headphones for $80 with 15% off.
Step 2 — Type and run this code.
price = 80
discount = price * 0.15
print(price - discount)
Step 3 — Output you should see.
68.0
Step 4 — What it means. The final price is $68.0. Writing it step by step keeps it easy to check.
Worked example B — Split items into boxes.
Step 1 — What we do. A warehouse in Rotterdam packs 53 items, 12 per box.
Step 2 — Type and run this code.
items = 53
print("Full boxes:", items // 12)
print("Items left:", items % 12)
Step 3 — Output you should see.
Full boxes: 4
Items left: 5
Step 4 — What it means. // gives full boxes (4) and % gives what is left (5). Logistics teams use this daily.
Worked example C — Round money values.
Step 1 — What we do. We split a £100 dinner bill between 3 friends.
Step 2 — Type and run this code.
share = 100 / 3
print(share)
print(round(share, 2))
Step 3 — Output you should see.
33.333333333333336
33.33
Step 4 — What it means. Division gives many decimals. round(share, 2) keeps 2 decimals for money: £33.33.
Ravindra Bagale's Tip
Use brackets to make the order of maths clear: (price - discount) * qty. Never guess the order.
Ravindra Bagale's Tip – मराठी
गणिताचा क्रम स्पष्ट करायला brackets वापरा: (price - discount) * qty. क्रमाचा अंदाज कधीच लावू नका.
Ravindra Bagale's Tip – हिंदी
गणित का क्रम साफ़ करने के लिए brackets लगाओ: (price - discount) * qty. क्रम का अंदाज़ा कभी मत लगाओ.