Python Programming · Foundations
Booleans
On this page 9 sections
In 30 seconds
Python's Boolean A value of Python's bool type: either True or False. Full entry → type, bool, represents truth values with exactly two instances: True and False. Python can also test the truth value The true-or-false result Python obtains when it tests an object. Full entry → of other objects: empty collections and numeric zero are falsey Describes a value whose truth test produces false. Full entry →, while most other objects are truthy Describes a value whose truth test produces true. Full entry →. This lets a program use a value as a yes-or-no test without changing what the value itself is.
Why this matters
Boolean reasoning is how a Python program represents whether a condition holds. It appears in validation, searches, loop guards, and expressions that choose a fallback value. Understanding truth testing avoids two common bugs: treating an empty value as though it were the same thing as every other falsey value, and expecting and or or to always produce True or False. It also makes short-circuit expressions safe and readable.
The college version
The Boolean type and truth testing
A Boolean value answers a truth question. Python's built-in type is bool, and it has exactly two instances: True and False. Capitalization matters: True is the Boolean object, whereas true is not a predefined Boolean name in Python. A Boolean is a value with its own type, so type(True) is bool.
Python also has a broader operation called truth-value testing Python's process for deciding whether an object counts as true or false in a Boolean context. Full entry →. Almost any object can be used where Python needs a yes-or-no result. The standard documentation describes the default rule: an object is considered true unless its class supplies __bool__() returning False, or supplies __len__() returning zero. That protocol is why a custom object can define what it means to be empty without giving up the rest of its behavior. An exception raised while computing one of those methods propagates; it is not silently treated as either answer.
Several built-in values are falsey: False, None, numeric zero such as 0 or 0.0, and empty sequences or collections such as '', [], {}, and set(). A nonempty string such as '0' is truthy because it contains a character; Python does not parse its text during truth testing. Likewise, [0] is truthy because the list has one element, even though that element is itself falsey. Everything not on the falsey side is normally truthy.
Truthy and falsey are descriptions of a value's behavior in a truth test, not alternate names for True and False. For example, bool([]) produces False, but the list remains a list; [] == False is false. This distinction matters when a program must tell apart an absent value, a numeric measurement of zero, and an empty collection. The separate Type Conversion lesson owns detailed conversion practice; here, bool() is useful only as a way to display the result of a truth test.
The bool and int nuance
Python documents bool as a subclass A type that inherits behavior from another type; Python's bool is a subclass of int. Full entry → of int. In many numeric contexts, False behaves like 0 and True behaves like 1; for example, True + True evaluates to 2, and isinstance(True, int) is true. That historical and language-level relationship can be useful when reading existing code or counting results, but it should not erase the conceptual distinction. A Boolean records truth, while an integer represents a whole number.
Clear code normally keeps that distinction visible. If an API or calculation genuinely needs an integer, use an explicit int(flag) conversion rather than relying on implicit numeric behavior. Conversely, do not use 1 and 0 as substitutes for True and False merely because they compare equal. Python's own documentation discourages relying on the numeric relationship. In particular, an equality result is not an identity claim: True == 1 is true, yet True is the Boolean singleton and 1 is an integer object. This lesson does not catalog equality, identity, arithmetic, or comparison operators; the Operators lesson treats those tools in depth.
The type relationship also does not mean that every expression involving Boolean values is best thought of as arithmetic. A list of checks such as [True, False, True] may be summed intentionally to count successful checks, but naming the result passed_count communicates the purpose. When the result is meant to steer later program behavior, preserve it as a Boolean. Good names such as has_access and is_empty also make the intended truth question easier to inspect.
Boolean operations and short circuiting
Python provides the logical operators and, or, and not. not performs a truth test and always returns a Boolean: not [] is True, while not [1] is False. and and or are different: they use truth testing to decide which operand A value or expression on which an operator acts. Full entry → to return. For x or y, Python returns x if x is truthy; otherwise it returns y. For x and y, it returns x if x is falsey; otherwise it returns y. Therefore 0 or 'fallback' evaluates to 'fallback', and [1] and 'next' evaluates to 'next', not to Boolean objects.
These operators are short-circuit operators. x or y evaluates y only if x is falsey, because a truthy x already decides which operand will be returned. x and y evaluates y only if x is truthy, because a falsey x already decides the result. This is observable behavior, not merely a speed improvement. A guard such as items and items[0] can avoid indexing an empty list: when items is empty, Python returns it and never attempts items[0]. Reversing the terms would not be safe.
Use short-circuit expressions when the returned operand is useful and the ordering is obvious. If a program needs a strict Boolean result, wrap the final value with bool() or use not where its inversion is actually intended. Conditional statements and branch structure are deliberately outside this lesson; the conditionals lessons own how a truth result selects code. The key point here is narrower: Python can test any object for truth, and its logical operators use that test while retaining useful operand values.

Eli explains
The same idea, in plain words
Explain it like I’m 10
A Boolean is Python's answer card for a question with only two choices: True or False. But Python can look at many ordinary values and decide whether they count as yes or no. An empty backpack counts as no; a backpack with even one pencil counts as yes. The pencil could be broken or small—the backpack is still not empty. In the same way, [0] is truthy because the list contains something, while [] is falsey because it does not.
The words and and or can make a decision early. If the first part of an and is already no, Python need not inspect the second part. If the first part of an or is already yes, it can stop there. That can protect a program from trying an operation that only makes sense after a prior check.
Picture it like this
Think of a hallway with two checkpoints. For an and rule, failing the first checkpoint means there is no reason to walk to the second. For an or rule, passing the first checkpoint means there is no reason to visit the second. An empty box is like an empty backpack: it counts as no, while a box containing any item counts as yes.
Where the picture stops working
Checkpoints usually deliver literal yes-or-no badges, but Python's and and or often return the original value they inspected, such as a string or list. The analogy also cannot show the custom __bool__() and __len__() methods that let a programmer define truth testing for a new kind of object.
Worked example
Suppose a program receives an optional list of names and wants the first name only when one exists. Running names = []; result = names and names[0] produces []. The empty list is falsey, so and returns that first operand and does not evaluate names[0]; no index error occurs. With names = ['Ada'], the list is truthy, so Python evaluates and returns names[0], which is 'Ada'. This is not a conditional-statement lesson: the example demonstrates the value returned by and and the order in which its operands are evaluated. If the program instead needs a strict Boolean answer, bool(names) returns False for the empty list and True for ['Ada'].
Key takeaway
Python has two Boolean objects, True and False, but it can truth-test almost any object. Learn which values are falsey, remember that and and or return operands and short-circuit, and use the bool/int connection deliberately rather than accidentally.
Quick check
3 questions here, of 5 in this lesson’s practice set. Answers stay hidden until you check.
Which two instances belong to Python's
What is the result of bool([0])?
Given items = [], what does items and items[0] evaluate to?
Study tools & related lessonsYou’ll learn to · Common mistakes · Easily confused · Key vocabulary · Related
You’ll learn to
- Define Python's two Boolean values.
- Explain how Python determines an object's truth value.
- Distinguish a Boolean value from a truthy or falsey object.
- Explain the
bool/intrelationship without treating them as interchangeable in clear code. - Trace
and,or, andnot, including their short-circuit behavior.
Common mistakes
Calling every truthy value
True.A nonempty list may be truthy, but it is still a list. Reserve
Truefor the Boolean object.Assuming
andandoralways return Boolean values.They return one operand; use
bool(...)when a strict Boolean is required.Treating the string
'0'as falsey because it looks like zero.A nonempty string is truthy. Its contents are not converted during a truth test.
Writing a risky expression before the guard that should protect it.
Put the safe truth test first so short circuiting can skip the risky second operand.
Using
1and0interchangeably with Boolean names in clear code.boolis anintsubclass, butTrueandFalsecommunicate truth intent more directly.
Easily confused
`False` vs. a falsey value such as `[]`
False is a Boolean object; an empty list merely produces false in a truth test and remains a list.
`not x` vs. `x and y` or `x or y`
not always returns a Boolean; and and or return one of their operands.
`bool` vs. `int`
bool is a subclass of int, so Boolean values work numerically as 0 and 1, but the types express different program meanings.
Key vocabulary
- Boolean
- A value of Python's
booltype: eitherTrueorFalse. - truth value
- The true-or-false result Python obtains when it tests an object.
- truthy
- Describes a value whose truth test produces true.
- falsey
- Describes a value whose truth test produces false.
- truth-value testing
- Python's process for deciding whether an object counts as true or false in a Boolean context.
- short circuit
- Skipping the second operand of
andororwhen the first operand already determines the result. - operand
- A value or expression on which an operator acts.
- subclass
- A type that inherits behavior from another type; Python's
boolis a subclass ofint.
Sources & references
- Built-in Types — Python 3 documentation — Python Software Foundation
- The Python Language Reference — 6. Expressions (Operator precedence) — Python Software Foundation
EliExplains lessons are original prose written from the open, credible references above. See Copyright & Licensing.
Researched 2026-08-19
Educational content only. It is not medical, legal or professional advice. Found an error? Tell us.

