Working With Boolean Logic
00:00 In this lesson, you’ll learn the basics of Boolean operations and a bit 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.
00:20
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. Booleanvexpressions are the types of expressions we use in if
and while
statements.
00:35
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 while
loop.
00:48
Here’s some terminology relevant to Boolean logic in Python Boolean is a type of value that can be either True
or False
. We signify that using the keyword bool
for that type, and it’s a subtype of the int
(integer) type.
01:04
There are two Boolean values, True
or False
, and in Python, those are capitalized. Internally, Python stores True
as 1
and False
as 0
.
01:17
A Boolean expression is an expression that returns either True
or False
. It does a computation and returns True
if the result of that computation is true, and False
if 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 operators are, in fact, and
, or
, and not
.
01:54
In the next lesson, you’ll start seeing the not
operator in use.
Become a Member to join the conversation.