Logical Operators - Combining Truth
6 / 15

What's the Function of Logical Operators?

"Logical operators let us combine multiple True/False statements. They answer: What happens when we need BOTH conditions true? Or just ONE? Or the OPPOSITE?"

The Three Logical Operators

AND

Connect dependent statements

True AND True → True
True AND False → False
False AND False → False

Both must be True

OR

Connect alternatives

True OR True → True
True OR False → True
False OR False → False

At least one must be True

NOT

Invert a statement

NOT True → False
NOT False → True

Flips the truth value

Interactive Circuit Diagram

CODE EXAMPLES Real-World Boolean Logic & Gate Mental Models + Explore
# AND - Both conditions must be true
age = 20
has_license = True
can_drive = age >= 18 and has_license  # True

# OR - At least one must be true
is_weekend = True
is_holiday = False
can_sleep_in = is_weekend or is_holiday  # True

# NOT - Flip the condition
is_raining = False
bring_umbrella = not is_raining  # True
Mental Model: Think of logical operators as gates:
  • AND is a strict bouncer — everyone needs ID
  • OR is flexible — show either ID or ticket
  • NOT is opposite day — yes means no, no means yes
Scarlet Blossoms
Woodland Milestone: You can now combine any number of conditions with and, or, and not! Next, let's use these conditions to branch your code with if-elif-else.
Logical operators combine conditions: 'and' requires both to be True, 'or' accepts either one, and 'not' flips True and False.
Wizard Guide