Python Comparison Operators
Comparison operators compare two values and produce a boolean answer: True or False. Whether you are checking if a password matches, verifying account balances, or testing game boundaries, comparison operators are your tools.
"Imagine a bouncer at a club door checking IDs. If your age >= 21, the bouncer says True (you may enter). If your age < 21, the bouncer says False (denied)."
Deep Dive: How It Works
== (Equal to): Checks if two values are identical. Note: Use == (two equals) for comparisons, not = (one equal, which assigns variables).
!= (Not equal to): Returns True if values are different, False if they match.
> (Greater than) and < (Less than): Standard mathematical comparisons.
>= (Greater than or equal to) and <= (Less than or equal to).
Chained Comparisons: Python uniquely allows chained checks like 10 < x < 20, which is equivalent to 10 < x and x < 20.
Syntax Blueprint
a == b # True if equal a != b # True if NOT equal a > b # Greater than a <= b # Less than or equal to
All comparison expressions evaluate directly to a boolean True or False.
Core Rules to Remember



Common Beginner Traps & How to Fix Them
Using single = in comparisons: if score = 100:Why it happens: Single equal sign is assignment and causes a SyntaxError inside if conditions.
How to fix: Always use double equals == for comparisons.
Live Interactive Example
Hit Run Code to see it liveYour Turn: Micro Challenge
No pressure! Edit the starter code below and test your solution with instant feedback.
Test equality comparison
Check if 25 * 4 is equal to 100 using == and print the result.
Finished reading and practicing?
Mark this lesson as completed to update your course progress.