This guide explains Arithmetic Operators: Addition, Subtraction, Multiplication, and Division through a focused example and practical reasoning. No prior knowledge of this specific operation is required.
Understanding the Concept
Python arithmetic uses +, -, *, /, //, %, and **. Each operator has a specific meaning, and the choice depends on whether you need totals, exact quotients, remainders or powers.
When You Would Use This
Calculate the price of supplies and the change from a payment.
Step-by-Step Example
unit_cost = 7
item_count = 4
payment = 40
subtotal = unit_cost * item_count
change = payment - subtotal
print("Subtotal:", subtotal)
print("Change:", change)
How the Example Works
Multiplication gives a subtotal of 28 and subtraction leaves 12 as change. The inputs are easy to replace because each quantity has its own name.
Example Output
Subtotal: 28
Change: 12
Try It Yourself
Add a two-unit delivery fee and recalculate the change.
Common Beginner Mistakes
- Expecting
^to mean exponentiation instead of bitwise XOR. - Accidentally using
/where//is appropriate for full groups. - Forgetting that operators follow precedence rules rather than always running left to right.
Key Takeaways
- Python arithmetic uses
+,-,*,/,//,%, and**. - Multiplication gives a subtotal of 28 and subtraction leaves 12 as change.
- Avoid this mistake: Expecting
^to mean exponentiation instead of bitwise XOR.