Skip to content

Python Logical Operators

How to use Python's and, or, and not operators to combine conditions in boolean expressions for effective decision-making in programs.

Logical Operators

Logical operators are the and, or, not operators.

They are used to combine conditional statements.

Operator Description Example
and True if both the operands are true x and y
or True if either of the operands is true x or y
not True if operand is false (complements the operand) not x

Examples

Logical AND

a = 10
b = 12
c = 0

print(a>0 and b>0 and c>0)  # False
print(a>0 and b>0 and c>=0) # True

Logical OR

a = 10
b = 12
c = 0

print(a>0 or b>0 or c>0) # True
print(a<0 or b<0 and c<0) # False
print(a<=0 or b<=0 and c<=0) # True

Logical NOT

a = 10
b = 12
c = 0

print(a>0)     # True
print(not a>0) # False
print(b>0)     # True
print(not b>0) # False
print(c>0)     # False
print(not c>0) # True
Navigation