🟰 Comparison Operators

5th Grade 💻 Coding

Comparison operators are symbols that compare two values and give back true or false — for example greater than, less than and equal to.

Free · US Letter · no sign-up
Google Classroom Save to Pinterest Email me

Python has six comparison operators: > greater than, < less than, >= greater than or equal to, <= less than or equal to, == equal to, and != not equal to. Every comparison like this is a question, and the answer is True or False.

The most common mix-up: a single equals sign (=) stores a value in a variable, while two (==) ask whether two values are equal. You can compare text too: "cat" == "cat" is True. In Scratch, the comparison blocks are the green ones in the Operators category.

For example

  • score >= 100 checks whether you’ve reached 100 points or more.
  • The != sign is handy for checking: answer != "yes" means “the answer is not yes.”
  • In a guessing game you check guess == secret to see if the guess is right, and guess < secret to say “Higher.”

📌 Remember: One = stores. Two == ask.

Quick quiz

  1. What does == mean in Python?

  2. What does != mean?

  3. What does 3 >= 3 give back?

🔎 Ask Thinkapedia another question