Booleans and comparisons
As programs grow, they need to make decisions. They need to compare values, test conditions, and decide which path to take next. Boolean expressions give us the raw material for those decisions, and they sit at the heart of Python’s control flow.
In this lesson, we orient ourselves around how Python represents truth and how comparisons produce values that can drive real program logic.
Boolean values
Python has two Boolean values: True and False. They represent the outcome of a question asked by the program.
A Boolean value is not text and not a number. It is its own distinct kind of value, used to express whether something is the case or not.
is_visible = True
has_rings = False
Once produced, Boolean values can be stored in variables, passed around, and combined with other expressions.
Comparison operators
Comparison operators compare two values and produce a Boolean result. The result tells us whether the comparison is true or false.
Python provides a small set of these operators, each with a clear meaning.
planet_count = 8
planet_count == 8
planet_count != 9
planet_count > 5
planet_count <= 10
Each expression evaluates to either True or False. Nothing else is produced.
Comparing numeric values
Numeric comparisons are the most straightforward. Numbers are compared by magnitude, just as we would expect.
orbital_period_days = 365
orbital_period_days > 200
orbital_period_days < 100
These comparisons are commonly used to gate behavior based on thresholds, limits, or ranges.
Comparing string values
Strings can also be compared. In this case, Python compares them lexicographically, based on their character order.
planet_name = "Mars"
planet_name == "Mars"
planet_name != "Earth"
String comparisons are most often used for equality checks, where an exact match is what matters.
Logical operators
Logical operators allow us to combine or modify Boolean expressions. They work with Boolean values and produce a Boolean result.
The most common operators are and, or, and not.
has_atmosphere = True
is_gas_giant = False
has_atmosphere and is_gas_giant
has_atmosphere or is_gas_giant
not is_gas_giant
These operators let us express more meaningful conditions by combining simpler ones.
Conclusion
We now know what Boolean values are, how comparisons produce them, and how multiple conditions can be combined into a single expression. That is enough to recognize and read the decision logic inside real Python programs.
With these ideas in place, we are ready to see how Python uses Boolean expressions to control which code runs and when.