Python Logical Operators (and, or, not)
Real-world decisions often require checking multiple conditions simultaneously. Can a user enter? They need an active account AND a verified email. Can a player respawn? If they have an extra life OR 100 gold coins. Python uses clean English words: and, or, not.
"Think of ordering lunch. If you say "I want pizza AND soda", you are only happy if you get both. If you say "I want tacos OR sushi", you are happy with either one. If you say "NOT spicy", you invert the condition."
Deep Dive: How It Works
and: Returns True ONLY if both conditions on the left and right are True. If either is False, the whole check is False.
or: Returns True if AT LEAST ONE condition is True. It only returns False if both sides are False.
not: Inverts whatever boolean follows it. not True becomes False, not False becomes True.
Short-Circuit Evaluation: Python is smart. In an "and" expression, if the first check is False, Python stops checking immediately because the result cannot be True. In an "or" check, if the first is True, Python skips the rest.
Syntax Blueprint
condition1 and condition2 # Both must be True condition1 or condition2 # At least one must be True not condition # Inverts True <-> False
Use plain English keywords and, or, not to compose compound logic.
Core Rules to Remember



Common Beginner Traps & How to Fix Them
Writing if x == 1 or 2:Why it happens: Python interprets this as (x == 1) or (2). Since 2 is truthy, this condition is ALWAYS True.
How to fix: Write out both sides: if x == 1 or x == 2: or use membership: if x in (1, 2):.
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.
Check eligibility with and
Given age = 20 and has_license = True, check if both are satisfied.
Print the boolean result of (age >= 18 and has_license).
Finished reading and practicing?
Mark this lesson as completed to update your course progress.