python / beginner
Snippet
Logical Operators
Logical operators (and, or, not) allow you to combine or invert boolean values to create complex conditions.
snippet.py
1
2
3
4
is_weekend = Trueis_busy = Falsecan_relax = is_weekend and not is_busyprint(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.