Skip to main content

Python Logical Operators

Logical Operators

Logical operators are the and, or, not operators.

They are used to combine conditional statements.

OperatorDescriptionExample
andTrue if both the operands are truex and y
orTrue if either of the operands is truex or y
notTrue 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

Table of Contents