8. Logical operations
Logical operators are used to combine conditional statements.
Logical operators test the truth value of their operands.
Operator |
Evaluates to ``True`` if: |
Example |
---|---|---|
and |
Both operands are true |
|
or |
At least one operand is true |
|
not |
Operand is false |
|
Examples of logical operations in Python:
score = 40
user = "Anne"
level = 2
print(score > 10 and user == "Anne")
print(score > 10 or level == 3)
print(not(level == 1))