Comparison Operators
Comparison operators ask questions about values.
Is this bigger? Are these the same?
The answer is always True or False.
These answers feed if checks and while loops.
Equal and not equal
== asks, are these the same value?
!= asks, are these different?
One equals sign assigns. Two equals signs compare.
Less and greater
< less than
> greater than
<= less than or equal
>= greater than or equal
Comparing text
Text compares alphabet style.
Case matters. A and a are not the same.
Chained comparisons
Python lets you write a range check in one line.
It reads like school math.
Using comparisons in if
Store the boolean, or put the comparison right in the if.
Common mix-up
Do not use = when you mean ==
= puts a value in a drawer.
== asks if two values match.
Tip: Say the comparison out loud. If it is a question, you want ==, not =.
Test yourself
Three quick questions made just for this lesson. Earn 10 XP per correct answer.