Python provides the OR operator. The OR operator can be also named as OR logic, OR bitwise operator, etc. But all of these point to the same operator. Two or more boolean values are calculated with OR logic. In this tutorial, we examine how to use OR operator. The
| sign is used for the OR operation.
OR Operator Syntax
Python OR operator has the following syntax where two or more boolean values can be used for the OR operation.
B1 | B2 | B3 | ...
- B1, B2, B3, and others are boolean values for the OR operation.
OR Operator Example
In the following example, we use two boolean values to OR them.
r1 = True | False r2 = True | True r3 = False| False r4 = False | True
OR Operator with More Than 2 Boolean Values
We can also use the OR operator in order to calculate more than 2 boolean values return for the OR logic operation. In the following example we use 3, 4 and 5 parameters for the OR operator.
r1 = True | False | False r2 = True | True | True r3 = False| False | True | False r4 = False | True | False | True | False