Hint: You can adjust the default video playback speed in your account settings.
Hint: You can set your subtitle preferences in your account settings.
Sorry! Looks like there’s an issue with video playback 🙁 This might be due to a temporary outage or because of a configuration issue with your browser. Please refer to our video player troubleshooting guide for assistance.

Using or With Boolean Expressions

00:00 Now let’s take a look at how we can use the or operator with Boolean expressions in Python.

00:08 To take the or of two Boolean expressions, you say <first expression> or <second expression>. This will evaluate to be True if either the first expression or second expression is True, and if they’re both False, the or will evaluate to be False.

00:22 Remember this is the inclusive OR, where if both are True the entire expression is viewed as True.

00:30 That can be summarized in this truth table. If expression 1 and expression 2 are both True, the entire expression evaluates to True, if the first one is True and the second one is False, the whole expression evaluates to True, and so on and so forth.

00:47 Let’s take a look at some examples of this. So if I provide it two expressions, 5 == 5 or 3 < 9, since both those expressions are True, the or will be True. If I provide one True and one False, 4 < 9 or 7 == 4, since the first expression was True, the whole thing is True.

01:13 If I provide an example where the first one is False but the second one is True,

01:20 4 < 2 or 9 == 9, the whole thing evaluates to be True. And if I provide two expressions that are False, 5 < 1 or 7 == 8, the whole thing evaluates to False.

01:43 An observation to make—and this will help you understand some of the future examples we’ll take a look at—is if expression 1 is True, the result is the value of expression 1.

01:58 If expression 1 is False, then the result is whatever the value of expression 2 is. And we will see how that’s useful when we start taking a look at how we can use or with expressions that aren’t Boolean expressions.

Become a Member to join the conversation.