Using or With Boolean Expressions
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
or will evaluate to be
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.
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
or will be
True. If I provide one
True and one
4 < 9 or 7 == 4, since the first expression was
True, the whole thing is
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.