True False Table for Boolean in Python
What Boolean Logic Actually Is in Python
Boolean logic is the backbone of every decision your Python code makes. It's not complicated—it's just true/false, on/off, yes/no. Python gives you three main operators to work with: and, or, and not. Master these and you can build any conditional logic you need.
Most beginners overthink this. You don't need computer science degrees. You need to memorize how these operators behave when you combine true and false values.
The AND Truth Table
The and operator returns True only when both operands are true. If one is false, the whole expression is false.
| A | B | A and B |
|---|---|---|
| True | True | True |
| True | False | False |
| False | True | False |
| False | False | False |
Think of it like a locked door that needs two keys. Both keys must work. One fails? Door stays shut.
Python Examples
True and True # Returns True
True and False # Returns False
False and True # Returns False
False and False # Returns False
The OR Truth Table
The or operator returns True if at least one operand is true. Only when both are false does it return false.
| A | B | A or B |
|---|---|---|
| True | True | True |
| True | False | True |
| False | True | True |
| False | False | False |
This is like an "either/or" situation. Give me pizza or pasta. Either works. Both work too. Only when you give me nothing does it fail.
Python Examples
True or True # Returns True
True or False # Returns True
False or True # Returns True
False or False # Returns False
The NOT Truth Table
The not operator flips the value. True becomes False. False becomes True. Simple.
| A | not A |
|---|---|
| True | False |
| False | True |
It's the inverter. Think of a light switch—flips the state every time.
not True # Returns False
not False # Returns True
Combining Multiple Operators
You can chain these together. Python follows a specific order: not runs first, then and, then or. Use parentheses to force your own order.
# Without parentheses - follows precedence
True or True and False # Evaluates: True or (True and False) → True
# With parentheses - you control the order
(True or True) and False # Evaluates: True and False → False
Always use parentheses when mixing and and or. Without them, you're relying on Python's precedence rules—and bugs from this are hard to spot.
Booleans from Comparison Operators
Comparisons return booleans too. This is where it gets practical.
5 > 3 # True
10 == 10 # True
7 <= 2 # False
"cat" != "dog" # True
You can combine comparisons with boolean operators:
age = 25
has_id = True
# Access granted only if both conditions met
can_enter = age >= 21 and has_id # True
Quick Reference: All Three Tables
| A | B | A and B | A or B | not A |
|---|---|---|---|---|
| True | True | True | True | False |
| True | False | False | True | False |
| False | True | False | True | True |
| False | False | False | False | True |
How to Get Started
Open a Python shell and test these yourself. That's it. No tutorials replace actual hands-on practice.
- Type
python3in your terminal - Try
True and False— see what you get - Try
not (True or False) - Build a simple condition:
x = 10; print(x > 5 and x < 20)
Test edge cases. Break things. See what happens when you mix types like 0 and 1 with boolean operators (Python treats 0 as False and 1 as True, but don't rely on this for readability).
Falsy Values to Watch
Python has values that evaluate as False in boolean context but aren't literally False. Know them:
None0(zero)""(empty string)[](empty list){}(empty dict)
Everything else is truthy. This matters when using and and or because they return the actual value, not just True or False.
# Returns the actual value, not a boolean
print(0 and "hello") # 0
print("cat" or "dog") # cat
print([] or [1,2,3]) # [1,2,3]
That behavior is useful but can trip you up if you expect pure booleans. Keep it in mind.