Logical Operators
Combine conditions when a decision depends on several requirements. Parentheses can make the intended grouping clearer to another developer.
Understand the idea
and requires both sides to pass, or accepts either alternative, and not reverses truth. Short-circuiting means a later expression may not run. A safe validation rule should state which missing or false values are legitimate rather than rely on a clever expression with hidden side effects.
Where to try it
Open this example with Try in playground. The code loads as editable text and does not run until you select Run. The first run downloads Python. Each run starts fresh; temporary files created by a script are not files on your PC.
A worked example
age = 19
has_booking = True
if age >= 18 and has_booking:
print("Entry allowed")
Read the result
The message appears because both requirements pass.
Try one change
Add an accompanied-minor exception with parentheses and test a person without a booking.