Comparison Operators - Making Judgments
5 / 15

Why Do We Need to Compare Things?

"Comparison operators allow us to make valuations about different values or express a relationship."

The Six Comparison Operators

<

Less Than

5 < 10

→ True

>

Greater Than

10 > 5

→ True

==

Equal To

5 == 5

→ True

!=

Not Equal To

5 != 10

→ True

<=

Less/Equal

5 <= 5

→ True

>=

Greater/Equal

10 >= 5

→ True

Interactive Comparison Lab

Click Compare to see result

Classic Trap: = (Assign) vs == (Compare)

Click a button below to test the difference between storing a value with = and asking a question with ==:

= (Single Equals: Assignment)
x = 5
Action: Puts 5 inside the variable box named x. Does not produce True/False!
== (Double Equals: Question)
x == 5
Question: "Is the value inside x equal to 5?" → Evaluates to True!
> Step 1: x = 5 (Memory box [x] now holds 5)
CODE EXAMPLES Expressing Relationships & Real-World Comparison Patterns + Explore
Mental Model: Comparisons are questions that always have True/False answers. They express relationships between values.
# Real-world examples
age = 18
is_adult = age >= 18  # True

score = 75
passed = score >= 60  # True
perfect = score == 100  # False

temperature = 32
is_freezing = temperature <= 32  # True

Common Use Cases

  • Checking age requirements: age >= 18
  • Testing equality: password == correct_password
  • Finding differences: current_score != previous_score
  • Range checking: 0 <= score <= 100
Marigold Bundle
Woodland Milestone: You've unlocked the power of judgment! Next, we'll combine multiple True/False questions together using Logical Operators.
Comparisons ask a yes-or-no question and always return True or False. Remember: = stores a value, while == checks if two values match.
Wizard Guide