![]() |
VOOZH | about |
Python OR is a logical operator keyword. The OR operator returns True if at least one of the operands becomes to be True.
Note:
Let’s start with a simple example to understand how "or" works in a condition.
Access denied
Explanation: The if condition is not being evaluated as True because neither of the conditions (age >= 18 or p) are True.
| Input 1 | Input2 | Output |
|---|---|---|
| True | True | True |
| True | False | True |
| False | True | True |
| False | False | False |
Let's explore some of the use cases of "or" keyword with examples.
In the if statement python uses the "or" operator to connect multiple conditions in one expression.
a is greater than b
"or" operator can be used inside loops to control execution based on multiple conditions.
Example :
g e e
"or" keyword is often used to set default values when dealing with empty or None variables.
Guest geeks
Explanation: