Skip to content
BENIBIX Learn

Comparison Operator

Development🧩 Programming ConceptsData and Variables

Also known as Relational Operator

A sign like ==, > or != that compares two values and answers true or false.

Think of it like

Think of it like a kitchen scale with two pans. It tells you which side is heavier, or if they match.

Example

A cinema site checks age >= 13 before it shows a teen film. Jack is 12, so the answer is False.

Why it matters

Every decision in code starts with a comparison. They are the questions an if asks.

Definition

A comparison operator checks two values and answers true or false. == asks if two values are equal and != asks if they differ. > and < ask which is bigger, and >= and <= allow a tie. The answer is always a boolean. Ifs and loops use these answers to decide what to do.

Example code

python
>>> age = 12
>>> age >= 13
False
>>> age == 12
True
Two questions about one age, and two true or false answers.

Common mistake

Writing = when you mean ==. One = stores a value; two of them compare.

Key takeaways

  1. 1
    Two values in. It looks at a left and a right.
  2. 2
    True or false out. The answer is always a boolean.
  3. 3
    Two equals signs. == compares; = stores.

Learn it properly