Calculating with Arithmetic Operators
Introduction
Welcome to Performing Operations on Python Data! In earlier courses, you learned how to store values in variables and perform simple arithmetic with +, -, *, and /. Now you are ready to expand your toolbox.
In this lesson, you will round out the full set of Python arithmetic operators by adding three new ones: floor division (//), remainder (%), and exponent (**). You will also see how Python decides which operation to perform first when several appear in the same expression, and how parentheses let you take control of that order whenever you need to.
The Seven Arithmetic Operators at a Glance
Before jumping into code, let us take a quick look at all seven arithmetic operators Python provides. Four of them are already familiar from earlier lessons; the other three will be new territory.
| Operator | Meaning | Example |
|---|---|---|
+ | Addition | 17 + 5 |
- | Subtraction | 17 - 5 |
* | Multiplication | 17 * 5 |
/ | True division | 17 / 5 |
// | Floor division | 17 // 5 |
% | Remainder | 17 % 5 |
** | Exponent (power) | 17 ** 5 |
Throughout this lesson, you will see the same two variables, a = 17 and b = 5, so we can focus on the operators themselves rather than the numbers behind them.
Familiar Operators with Variables
Let's start with the four operators you already know, now applied directly to variables. As you may recall from earlier, you can freely use variables inside arithmetic expressions, and Python simply looks up their current values before running the calculation.
Each print first computes a value, then displays it on its own line. Notice one important detail on the last line: a / b produces 3.4, a float, even though both a and b are whole numbers. This matches what you saw before: the / operator always returns a float, no matter what you divide.
Floor Division with //
Sometimes you want only the whole part of a division and do not care about anything after the decimal point. That is exactly what floor division does: the // operator divides two numbers, then rounds the result down to the nearest whole number.
Since a / b equals 3.4, rounding down gives you 3. For positive numbers like these, rounding down looks the same as keeping the whole part and discarding the rest:
This is handy whenever you need whole counts of something. For example, if you have 17 apples and want to pack them into boxes of 5, a // b tells you that you can fill 3 complete boxes. The leftover apples, as you will see next, come from a different operator.
Finding the Remainder with %
Raising to a Power with **
Operator Precedence and Parentheses
When several operators appear in the same expression, Python evaluates them in a fixed order, much like the rules from math class. This is known as Operator Precedence. From highest to lowest priority:
**(exponent) is evaluated first- Then
*,/,//, and% - Finally
+and-
To override this default order, you wrap parts of an expression in parentheses, and Python will always compute what is inside them first.
Without parentheses, a + b * 2 would first compute b * 2 (giving 10) and then add a, resulting in 27. With parentheses, the addition happens first: (17 + 5) * 2 becomes 22 * 2.
A side-by-side view makes the different evaluation order easier to spot:
So the final line of output is:
Conclusion and Next Steps
You now have the complete set of Python arithmetic operators at your fingertips: +, -, *, /, //, %, and **. Alongside them, you have seen how Python decides which operator to apply first when several appear together, and how a well-placed pair of parentheses can reshape that order to match exactly what you intend. Together, these tools let you translate almost any everyday calculation into Python code with confidence.
Next up is a short set of hands-on practices designed to help you apply what you just learned. You will get to try these operators on your own values, explore how they behave together, and gain a feel for when each one is the right tool for the job. Take your time with each exercise — the ideas here will show up again and again throughout the rest of the course.

