Operators

Module 2 · Operators · Lesson 2 of 4

Basic operators

An operator is a symbol that operates on values — just as + adds two numbers in arithmetic. Python has seven for everyday maths. Here they are, each with a worked example:

The seven arithmetic operators
**Exponentiation2 ** 38
*Multiplication7 * 321
/Division7 / 23.5
//Floor division7 // 23
%Modulo (remainder)7 % 21
+Addition7 + 310
-Subtraction7 - 34

Try them yourself — and watch the type of each result closely:

Run it yourselfruns in your browser · Python
main.py

A pattern runs through nearly all of them — the int/float rule: when both operands are integers, the result is an integer; if even one is a float, the result is a float. Exponentiation (**), multiplication and the rest all follow it.

There's one exception. Plain division (/) always gives a float — even 4 / 2 is 2.0, not 2. When you need a whole-number result, reach for floor division (//) instead. It throws away the fractional part — but carefully: it always rounds down, toward the smaller integer, which matters once negatives show up.

Run it yourselfruns in your browser · Python
main.py

See the last line? -6 // 4 is -2, not -1. The true answer is -1.5, and rounding down from there lands on -2. (You'll also hear floor division called integer division.)

The last operator is the odd one out: modulo (%), which has no everyday arithmetic symbol. It gives the remainder left after a floor division — what couldn't be evenly divided away.

14 % 4
=2

Three full groups of 4 (that's 12), and the 2 that can't fill a fourth group are the remainder.

And a hard rule, no exceptions: never divide by zero — not with /, //, or %. Python stops with a ZeroDivisionError every time.

One last subtlety about + and -: most operators are binary — they sit between two values, like 7 - 3. But - can also be unary, taking a single value to flip its sign, as in -7. That difference becomes important next, when we sort out which operator goes first.