Skip to content

Python Logical Operators

Syntax

Logical operators in Python (and, or, not) are used to combine or modify Boolean expressions.

and # AND
or # OR
not # NOT

Example

# Checking if a number is within a range
number = 15
is_in_range = number > 10 and number < 20
print(f"Is the number within the range 10-20? {is_in_range}")