In Python, a condition does not have to be literally True. Python asks whether a value is truthy or falsy, and and, or, and not all work from that rule. The part that surprises most beginners is that and and or return one of the values you gave them, which may be a string, a number, or a list rather than True or False.
What a Boolean value is
Python has two Boolean values, True and False. A comparison such as age >= 18 produces one of them, so a Boolean is often the result of asking a question about your data.
As an Amazon Associate I earn from qualifying purchases.
age = 20
is_adult = age >= 18
print(is_adult) # True
print(type(is_adult)) # <class 'bool'>
The official Python language reference, in its Boolean operations and comparisons sections, defines these rules. The examples here use Python 3 and follow the documentation for the 3.14 series, which the official docs currently label 3.14.7.
Recommended Free Tools
How Python decides whether a value is true in a condition
An if statement does not require the condition to be exactly True. Python calls the value’s truth value, which is what bool() returns for it. The language reference lists these values as false: False, None, numeric zero (such as 0 and 0.0), empty strings, and empty containers such as lists, tuples, dictionaries, and sets. Every other value is true, unless the object’s class customizes its truth value with a __bool__ or __len__ method.
#1 Best Overall
name = ""
if name:
print("Hello,", name)
else:
print("No name given") # this line runs, because "" is falsy
| Value | bool(value) | Why |
|---|---|---|
True |
True | Boolean value itself |
None |
False | Listed as false in the language reference |
0 |
False | Numeric zero is false |
0.0 |
False | Floating-point zero is also numeric zero |
"" |
False | Empty string |
" " |
True | A space is a non-empty string |
[] |
False | Empty container |
[0] |
True | Non-empty list; the value inside does not matter |
The last two rows are the ones beginners most often misread. A list containing a zero is not empty, so it is truthy.
not: the negation operator, which always returns a Boolean
In Python, not is an operator keyword, not a function you call with a name in parentheses. It is written directly before its operand. The Python language reference, in the Boolean operations section, states:
“The operator
notyieldsTrueif its argument is false,Falseotherwise.”Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
print(not "") # True
print(not [1, 2]) # False
print(not 0) # True
When to use not instead of checking for False
Most of the time your data is not a literal False. It is a list, a string, or a value that might be None, and you want to ask whether it is missing or empty. not applies Python’s truth rule to any object, so one test covers all of those cases:
Rank #2
items = []
if not items:
print("Nothing to show") # runs, because [] is falsy
Comparing with False does not do the same thing. [] == False is False in Python, so if items == False: would miss the empty list entirely. The same is true of None and empty strings. Use not when you mean “this value is empty, missing, or zero” and use == False only when the value is a real Boolean that you want to compare directly.
and and or: they return operands, not new Booleans
Both operators use short-circuit evaluation. Python evaluates the left operand first, and it may skip the right operand entirely:
a and breturnsaifais falsy. Otherwise it evaluates and returnsb.a or breturnsaifais truthy. Otherwise it evaluates and returnsb.
The result is therefore the last value Python evaluated. That value is not converted to True or False.
The Tool Desk
Outbyte Driver Updater FREEScan for outdated or missing drivers - takes under a minuteDriver Scan →Outbyte PC Repair FREERepair Windows errors before they cause bigger problemsFix Now →| Expression | Result | Why |
|---|---|---|
"" or "Guest" |
"Guest" |
Left side is falsy, so or returns the right side |
"Ana" or "Guest" |
"Ana" |
Left side is truthy, so the right side is never evaluated |
0 and 5 |
0 |
Left side is falsy, so and stops and returns it |
3 and 5 |
5 |
Left side is truthy, so the right side is returned |
[] and [1] |
[] |
The empty list is falsy, so it is returned unchanged |
False and 1/0 |
False |
Short-circuit: 1/0 is never evaluated, so no error occurs |
The name = name or “Guest” pattern
name = name or "Guest"
This line is common and useful, but it replaces any falsy value, not only missing ones. An empty string and 0 both trigger the default. If 0 is a legitimate value in your program, write an explicit check such as name = "Guest" if name is None else name instead.
Rank #3
Where the Boolean-only table applies
When both operands are actual Booleans, the results match the familiar truth table. This is the only case where the answer is always True or False:
| A | B | A and B | A or B |
|---|---|---|---|
| False | False | False | False |
| False | True | False | True |
| True | False | False | True |
| True | True | True | True |
Operator precedence: not, and, or
When an expression has several operators, Python groups them by precedence. From tightest to loosest binding, the relevant levels are:
- Comparisons such as
==,<, and>= notandor
Because and binds tighter than or, the expression on the first line below is read as the second:
Quick wins for a faster PC:
Fix the driver behind crashes, sound loss and screen glitchesFind Drivers →Repair Windows errors before they cause bigger problemsFix Now →print(True or False and False) # True
# parsed as: True or (False and False)
print((True or False) and False) # False
# parentheses change the grouping
Likewise, not 1 == 2 is read as not (1 == 2), which is True. Parentheses make the intended grouping visible to the next person who reads the code, including you in a month.
Rank #4
Chained comparisons
Python allows a comparison to be chained, which is how range checks are normally written:
score = 85
print(70 <= score <= 89) # True
The expression means 70 <= score and score <= 89, and score is evaluated only once. Beginners often write the same check with two separate conditions joined by and, which is also correct, but the chained form is shorter and matches how the value is described in the language reference.
Common confusions to clear up
- Assignment versus equality.
=stores a value in a name, and==asks whether two values are equal.if score = 90:is a syntax error in a condition, which is Python’s way of catching the mistake. - Testing against True.
if ready == True:works, butif ready:is the idiomatic form, because it accepts any truthy value. - Identity versus equality.
ischecks whether two names refer to the same object, while==compares values. ForNone, the convention isif value is None:. - Expected Boolean results. If you assume
andandoralways returnTrueorFalse, the first example that prints a string or a number will look like a bug. It is documented behavior.
Check the behavior yourself
You can verify every example above in an interactive session without creating a file:
- Open a terminal and start Python 3 by typing
python3. On Windows, the launcher is usuallypy. - At the
>>>prompt, type an expression such as"" or "Guest"and press Enter. Python prints the value it returned. - Type
bool("")next and compare the output. Repeat withbool([0])to see the case that surprises most beginners. - Type
exit()or press Ctrl+D (Ctrl+Z then Enter on Windows) to leave the session.
For the authoritative wording, read the Boolean operations, comparisons, and operator precedence sections of the official Python language reference. Those sections describe the rules used throughout this article.
Quick Recap
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.




