Python or Operator
In Python, Logical OR Operator takes two boolean values or expressions as operands and returns the result of their logical OR operation. The logical OR operator returns True if at least one of the operands is True, else it returns False.
Syntax
The syntax to find the logical OR of two values: x
and y
using OR Operator is
x or y
The above expression returns a boolean value.
Examples
1. Logical OR operation of two values
In the following program, we take two boolean values in x
, y
; and find the result of their logical OR operation.
main.py
x = True
y = False
result = x or y
print(result)
Output
True
2. OR Operation for all combinations of operand values
In the following program, we take two boolean values in x
, y
; and find the result of their OR operation, for all the combinations of the operand values.
main.py
#both operands are True
x = True
y = True
result = x or y
print(result) #True
#one of the operands is True
x = True
y = False
result = x or y
print(result) #True
x = False
y = True
result = x or y
print(result) #True
#both operands are False
x = False
y = False
result = x or y
print(result) #False
Output
True
True
True
False
3. Logical OR operation of two boolean expressions
In the following program, we take two integer value in x
, and check if x is greater than 10 or exactly divisible by 3.
main.py
x = 6
if x > 10 or x % 3 == 0 :
print('x is greater than 10 or divisible by 3.')
Output
x is greater than 10 or divisible by 3.
Conclusion
In this Python Tutorial, we learned about Logical OR Operator, its syntax, and usage, with examples.