- These operators are used to combine multiple conditions.
| Operator | Meaning | Example | Result |
|---|
| and | Logical AND | (5 > 3) and (2 < 4) | True |
| or | Logical OR | (5 < 3) or (2 < 4) | True |
| not | Logical NOT | not (5 > 3) | False |
- These operators compare values and return True or False.
| Operator | Meaning | Example | Result |
|---|
| > | Greater than | 5 > 3 | True |
| < | Less than | 5 < 3 | False |
| >= | Greater than or equal to | 5 >= 5 | True |
| <= | Less than or equal to | 5 <= 3 | False |
| == | Equal to | 5 == 5 | True |
| != | Not equal to | 5 != 3 | True |
- Example: Both comparisons need to be True for the if statement to be True.
1temperature = 75
2forecast = "rain"
3
4if temperature < 80 and forecast != "rain":
5 print("Go outside!")
6else:
7 print ("Stay inside!")