capypad
0 day streak
python / beginner
Snippet

Logical Operators

Logical operators (and, or, not) allow you to combine or invert boolean values to create complex conditions.

snippet.py
python
1
2
3
4
is_weekend = True
is_busy = False
can_relax = is_weekend and not is_busy
print(can_relax)
Breakdown
1
is_weekend = True
Assigns a boolean True value to a variable.
2
is_busy = False
Assigns a boolean False value to another variable.
3
can_relax = is_weekend and not is_busy
Combines variables: True AND (NOT False) results in True.
4
print(can_relax)
Outputs the final boolean result to the console.