Booleans, Comparisons, and Logic
A boolean is a value that is either True or False. Booleans are the answers to yes/no questions, and they are what drives every decision your programs make. In this lesson you will produce booleans by comparing values and combine them with logic.
What You'll Learn
- The
TrueandFalsevalues - Comparison operators that produce booleans
- Combining conditions with
and,or,not - Truthy and falsy values
True and False
Note the capital letters: True and False, not true or false.
Comparison Operators
Comparisons ask a question and answer with a boolean:
Watch out: = assigns a value, but == compares two values. Mixing them up is the most common beginner bug.
Chained Comparisons
Python lets you write a range check the way you would in math:
Combining Conditions: and, or, not
andisTrueonly if both sides are trueorisTrueif at least one side is truenotflips a boolean
Truthy and Falsy
In a yes/no context, some values act like False even though they are not literally False. Empty things (0, '', [], None) are falsy; almost everything else is truthy:
This is why you can write if my_list: to mean "if the list has anything in it," which you will use often.
Key Takeaways
- Booleans are
TrueorFalse(capitalized) ==,!=,<,>,<=,>=compare values and return booleans=assigns,==comparesand,or,notcombine conditions- Empty values are falsy; non-empty values are truthy

