Working With Boolean Logic in Python
00:00 In this lesson, you’ll learn the basics of Boolean operations and a bit about how Python implements them.
00:08 Boolean logic is named after George Boole, who developed a whole system of mathematics based on two values called true and false and the operations on them (AND, OR, and NOT).
Since computers work in binary—two values, although we call them one and zero—Boolean algebra became the natural way to design and build computers. Boolean expressions are the types of expressions we use in
The use of Boolean operators can allow you more precise and sometimes more complicated conditions to describe which branch of an
if statement to execute or when to repeat an iteration in a
Here’s some terminology relevant to Boolean logic in Python. Boolean is a type of value that can be either
False. We signify that using the keyword
bool for that type, and it’s a subtype of the
int (integer) type.
There are two Boolean values,
False, and in Python, those are capitalized. A Boolean expression is an expression that returns either
It does a computation and returns
True if that result of that computation was true, or
False if the result of that computation was false.
The three Boolean operators are
and, which connects two expressions,
or, which also connects two expressions, and
not, which only acts on a single expression.
In Python, the keywords that we use for these Boolean operations are, in fact,
In the next lesson, you’ll start seeing the
and operator in use.
Become a Member to join the conversation.