---
title: Comparison Operators in Python
source: https://app.sythra.ai/learn/python/comparison-operators-python
topic: Python
updated: 2026-08-12
publisher: Sythra (https://app.sythra.ai)
---

# Comparison Operators in Python

Comparison operators in Python (==, !=, <, >, <=, >=) compare two values and produce a boolean True or False, which you then combine with and, or, and not to build the conditions used in if statements.

_Source: [https://app.sythra.ai/learn/python/comparison-operators-python](https://app.sythra.ai/learn/python/comparison-operators-python) — free to read on Sythra._

## Key points

- == compares for equality; = assigns a value — mixing them up is a classic bug
- x % y gives the remainder of x divided by y, useful for checking even/odd or perfect division
- and requires both sides true; or needs only one side true; not flips a boolean
- Python treats any non-zero number as truthy and zero as falsy
- There is no =< or => in Python — only <= and >=

Every program you've written so far does the exact same thing every single time you run it — same input, same output, no thinking, no choice involved. But a real app needs to _look at something, decide something, and react differently_ depending on what it found. That decision-making starts with **comparison operators in Python** and the boolean values they produce.

This page covers the modulus operator, every comparison operator, and how to combine conditions with `and`, `or`, and `not` — the building blocks for [if statements](/learn/python/conditionals-in-python).

## What you will learn

- What the modulus operator `%` actually computes
- Every comparison operator: `==`, `!=`, `>`, `<`, `>=`, `<=`
- The classic `=` vs `==` bug that trips up every beginner
- How to combine conditions with `and`, `or`, `not`
- Why Python treats non-zero numbers as truthy

## The modulus operator: the remainder you forgot about

You already know how to divide numbers, but there are actually _two_ results hiding inside every division problem. When you divide 7 by 3, the answer is 2 — but there is 1 left over that did not fit. That leftover piece is called the **remainder**. Python gives you the remainder using the `%` symbol, the **modulus operator**:

```python
quotient  = 7 / 3    # 2.3333...   the result of dividing
remainder = 7 % 3    # 1            the leftover piece
```

Think of it like sharing sweets. If you have 7 sweets and 3 friends, each friend gets 2 sweets, and you have 1 sweet left over that does not divide evenly — that leftover 1 is exactly what `7 % 3` gives you.

The most common use of `%` is checking whether a number divides _perfectly_, with nothing left over. If `x % y` equals zero, then `y` divides evenly into `x`:

```python
10 % 2    # 0   (10 divides evenly by 2, so it's even)
10 % 3    # 1   (10 does NOT divide evenly by 3)
```

You can also use it to pull out specific digits from a number, since the last digit of any number is just whatever is left after dividing by 10:

```python
x = 12345
x % 10     # 5    just the last digit
x % 100    # 45   the last two digits
```

You will reach for `%` more often than you expect — especially when working with even/odd numbers, repeating patterns, or clocks.

## Boolean expressions: questions with yes or no answers

Before a program can make a decision, it needs to be able to ask a question. In Python, every question has exactly two possible answers: **True** or **False**. An expression that gives you one of these two answers is called a **boolean expression**.

```python
5 == 5    # True    (yes, 5 is equal to 5)
5 == 6    # False   (no, 5 is not equal to 6)
```

`True` and `False` are not words or strings — they are a special type of value in Python called `bool`. There are only two of them in the whole language, and every decision your program makes comes down to one of them.

| Operator | Meaning | Example |
| --- | --- | --- |
| == | equal to | x == y |
| != | not equal to | x != y |
| > | greater than | x > y |
| < | less than | x < y |
| >= | greater than or equal | x >= y |
| <= | less than or equal | x <= y |

> **The trap that catches every beginner:** 

## Logical operators: combining conditions

Sometimes a single question is not enough — what if you need to check two things at once? Python gives you three tools for combining conditions, and they work almost exactly like the same words in English:

```python
x > 0 and x < 10          # True only if BOTH are true (x is between 0 and 10)
n % 2 == 0 or n % 3 == 0   # True if AT LEAST ONE is true (n divides by 2 or by 3)
not (x > y)                # True if the thing after not is FALSE
```

- `and` requires _both_ sides to be true. If either side is false, the whole thing is false.
- `or` only needs _one_ side to be true. It is only false when both sides are false.
- `not` simply flips whatever comes after it — true becomes false, false becomes true.

For short-circuit evaluation, truth tables, and the difference between `and`/`or` versus the bitwise `&`/`|`, see the dedicated [Logical Operators in Python](/learn/python/logical-operators) page.

## Truthiness: what counts as true or false beyond bool

Python is flexible about what counts as "true" or "false" outside of actual booleans. Any non-zero number is treated as true, and zero is treated as false:

```python
17 and True    # True    (17 is non-zero, so it counts as true)
0 and True     # False   (0 is treated as false)
```

This flexibility can be useful later, but for now — until you are comfortable — stick to writing out your conditions explicitly with `==`, `!=`, `>`, and so on. It keeps things clear.

## Common mistakes

- Writing `x = 5` when you meant to compare with `x == 5`
- Writing `=<` or `=>` instead of `<=` and `>=`
- Forgetting that `and` needs both sides true, while `or` only needs one
- Assuming `%` gives you the division result instead of the remainder

> **Practice with Sythra:**  [Practice with AI tutor](https://app.sythra.ai/pricing)

## FAQ

### What is the difference between = and == in Python?

A single = assigns a value to a variable, like x = 5. A double == compares two values and returns True or False, like x == 5. Confusing the two is one of the most common beginner mistakes.

### What does the % operator do in Python?

The % (modulus) operator returns the remainder of dividing the left number by the right number. For example, 7 % 3 equals 1. It's commonly used to check if a number divides evenly (x % y == 0).

### What is the difference between and and or in Python?

and returns True only if both conditions are true. or returns True if at least one condition is true. not flips a boolean value from True to False or vice versa.

### Why does Python treat 0 as False?

Python has a concept called truthiness: any non-zero number is treated as true in a boolean context, while zero is treated as false. This lets you write conditions like if count: instead of if count != 0:.

### Is there a =< or => operator in Python?

No. Python only supports = (greater than or equal), always with the comparison symbol first.

## Related

- [Conditionals in Python (if, elif, else)](https://app.sythra.ai/learn/python/conditionals-in-python) — if, elif, else, pass, and nested conditionals.
- [Logical Operators in Python](https://app.sythra.ai/learn/python/logical-operators) — Deep dive into and, or, not, short-circuiting, and truth tables.
- [Operators and Operands in Python](https://app.sythra.ai/learn/python/operators-operands) — The arithmetic operators these comparisons build on.
- [Python course hub](https://app.sythra.ai/learn/python) — All free Python explainers and the path into Agentic practice.

---

Written by Sythra — Learn machine learning by building. Practice this topic with Sythra's AI tutor: https://app.sythra.ai/pricing
