# Operators in Python

> The signs that do maths, compare two values, and join true or false answers. Why == is not =, and what and, or and not do.

**Course:** [Programming Basics](https://learn.benibix.com/learn/development-concepts)  
**Time:** 12 min

**After this lesson you can:**

- Do maths with + - * / and also // and %
- Compare two values with == and !=
- Join tests with and, or and not

## Which signs do maths, compare and combine

An operator is a sign that works on values and gives back a result. In 7 + 2, the + is the operator and the answer is 9. Python's operators fall into three groups: ones that do maths, ones that compare, and ones that join true and false answers together.

The arithmetic operators do maths. + adds, - takes away, * multiplies and / divides. Two more are worth learning early. // divides and drops the remainder, so 7 // 2 gives 3. % gives only the remainder, so 7 % 2 gives 1. ** raises to a power, so 2 ** 10 gives 1024.

% is more useful than it looks. A number is even when n % 2 gives 0. A clock wraps round with hour % 12. Python also follows the usual order from school maths: 2 + 3 * 4 gives 14, not 20, because the multiplying comes first. Brackets change the order.

The comparison operators compare two values and answer True or False. == asks if two values are equal and != asks if they are different. >, <, >= and <= compare sizes. So 5 > 3 gives True, and "cat" == "Cat" gives False, because capital letters count.

The logical operators join true and false answers. In Python they are the words and, or and not. a and b is True only if both are True. a or b is True if at least one is. not flips True to False. So age >= 13 and age <= 19 is True for a teenager.

Python stops early when it can. In a and b, if a is False, the whole answer must be False, so b is never checked. That lets you write safe tests like name and name[0] == "A", where the second part runs only when name is not empty.

The classic mistake is writing = when you mean ==. One sign stores a value. Two signs compare. Python refuses if x = 5: with a SyntaxError, which is a kindness, because some languages run it and quietly store 5 instead.

## The three kinds of operator

| Kind | Signs | Example and result |
| --- | --- | --- |
| Arithmetic | + - * / // % ** | 7 // 2 gives 3 |
| Comparison | == != > < >= <= | 5 > 3 gives True |
| Logical | and or not | True and False gives False |

![Three columns. Arithmetic shows 7 // 2 giving 3 and 7 % 2 giving 1. Comparison shows 5 > 3 giving True and 4 == 5 giving False. Logical shows a small grid: True and True gives True, True and False gives False, True or False gives True.](https://learn.benibix.com/diagrams/prog-operators.svg)

### Example: Emma splits a bill

Emma has 23 sweets to share between 4 friends. 23 // 4 gives 5 each, and 23 % 4 gives 3 left over.

She also checks who gets a free drink: age < 12 or age > 65. For a 70 year old the test gives True, and for a 30 year old it gives False.

**Words in this lesson:** [Operator](https://learn.benibix.com/term/development/operator), [Arithmetic Operator](https://learn.benibix.com/term/development/arithmetic-operator), [Comparison Operator](https://learn.benibix.com/term/development/comparison-operator), [Logical Operator](https://learn.benibix.com/term/development/logical-operator)

**Question:** What does 17 % 5 give in Python?

**Answer:** 2. % gives the remainder after dividing. 5 goes into 17 three times, which makes 15, and 2 is left over.

---

Source: https://learn.benibix.com/learn/development-concepts/operators-in-python
Author: Behnia Zarei (a developer in Vienna, Austria, who builds and teaches data, AI and business intelligence at BENIBIX)
Publisher: BENIBIX Learn (https://learn.benibix.com/)
Last updated: 2026-11-19
Licence: CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Quote freely with attribution.
