Loading video player…

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).

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. Boolean expressions are the types of expressions we use in if and while statements.

00:37 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:50 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:07 There are two Boolean values, True and False, and in Python, those are capitalized. A Boolean expression is an expression that returns either True or False.

01:20 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.

01:30 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.

01:45 In Python, the keywords that we use for these Boolean operations are, in fact, and, or, and not.

01:54 In the next lesson, you’ll start seeing the and operator in use.

Become a Member to join the conversation.