Booleans and None

True, False, and ‘nothing’

Beginner 9 min

In this lesson

A boolean is a value that is either True or False — how Python represents a yes/no decision. You’ll learn how comparisons produce booleans, which values count as ‘truthy’, and what the special value None means.

Explain it like I’m 5

A boolean is a yes/no answer. None is different — it’s Python’s way of saying ‘there’s nothing here yet’, which is not the same as ‘no’.

Booleans come from comparisons

Comparisons produce a boolean: 3 > 1 is True, 2 == 5 is False. The comparison operators are == (equal), != (not equal), and < > <= >=. These are the conditions you’ll feed to if statements next unit.

Example
print(3 > 1)
print(2 == 5)
print(7 != 4)
Output
True
False
True
Each comparison evaluates to True or False.

Truthiness

Python also treats non-boolean values as true-ish or false-ish in a yes/no context. Falsy values include 0, 0.0, "" (empty string), [] (empty list), {} (empty dict), and None. Almost everything else is truthy. This lets you write if name: to mean ‘if name isn’t empty’.

Example
name = ""
if name:
    print("Got a name")
else:
    print("Name is empty")
Output
Name is empty
Truthiness in action.

Combining conditions: and, or, not

and is True only if both sides are; or is True if either side is; not flips a boolean. Example: age >= 13 and age <= 19 checks the teen range. Use parentheses when mixing them, for clarity.

Example
age = 16
is_teen = age >= 13 and age <= 19
print(is_teen)
print(not is_teen)
Output
True
False
Building and negating a boolean.

Set a score, then print whether it's a passing score (50 or above) AND not a perfect 100.

score = 72
print(score >= 50 and score != 100)

None: the absence of a value

None represents ‘no value’. A function that doesn’t explicitly return anything returns None. Crucially, None is not False, not 0, and not "" — it’s its own thing. Test for it with is: if result is None:.

Short-circuiting and chained comparisons

Two conveniences make boolean logic both faster and more readable. First, and and or short-circuit: in a and b, if a is already false, Python never bothers checking b — the answer can’t change. This lets you guard a risky test, e.g. count > 0 and total / count > 5 safely avoids dividing when count is zero.

Second, you can chain comparisons the way maths does: 0 <= score <= 100 is true only when score sits in that range — no and required.

Example
age = 20
print(0 <= age <= 17)
print(age >= 18 and age < 65)

user = ""
print(user or "guest")
Output
False
True
guest
A chained comparison, and or supplying a fallback.

Common mistake: Treating None like False or 0

Why it happens:

They’re all falsy, so they behave alike in an if, but they are different values. None == 0 is False.

How to fix it:

When you specifically mean ‘not set’, test with is None. Reserve 0 and False for actual numbers and booleans.

Which value is truthy?

What does (5 > 3) or (1 > 9) evaluate to?

Mini exercise (easy)

Given a variable stock, print True if it is greater than 0, otherwise False — using a single comparison.

Do it here. Finish the code below and press Run to try your answer right in the browser — no setup needed.

stock = 5
in_stock = False    # TODO: True if stock is greater than 0
print(in_stock)

What to learn next

You learned how comparisons produce True or False, the truthiness of everyday values, how to combine conditions, and how None differs from False, 0, and empty. You wrote a comparison, stock > 0, to decide whether an item was in stock.

You’ve now used several operators in passing, so it helps to see the whole toolkit in one place. Operators tours the arithmetic, comparison, logical, assignment, membership, and identity operators, plus precedence and when parentheses make intent clear. When you’re ready, continue to the next lesson.