Chain booleans with the or keyword #
The or keyword is different from the and that or returns True if any conditions in the expression evaluate to True. For the expression to be False, all conditions must be False.
For example:
x = 5
y = 10
z = 15
result = x < y or y < z # True or True
print(result) # Output: True
result_2 = x < y or y == z # True or False
print(result_2) # Output: True
result_3 = x == y or y == z # False or False
print(result_3) # Output: False
In the above example, the variable result and result_2 are both True, since at least one of the conditions are True. However, the variable result_3 is False because all of the conditions are False.
Exercise #
Use the keyword or to set the variables' values
Tests #
- Variable
trueshould beTrue - Variable
falseshould beFalse - Use the keyword
orto set the variabletrue - Use the keyword
orto set the variablefalse
Getting Started with Python
Data Types
Python Functions
Statements in Python
Basic Debugging in Python
Basic Algorithm
Object-Oriented Programming
Error Handling
Intermediate Algorithm
Python Modules