capypad
0 day streak
python / beginner
Snippet

Logical Operators: and & or

Logical operators allow you to check multiple conditions at once. 'and' requires both to be true, while 'or' requires at least one to be true.

snippet.py
python
1
2
3
4
age = 20
has_ticket = True
if age >= 18 and has_ticket:
print("Entry allowed")
Breakdown
1
if age >= 18 and has_ticket:
Checks if the age is at least 18 AND the ticket status is True.
2
print("Entry allowed")
Executes only if both conditions in the line above are met.