PYTHON LOGICAL OPERATORS
INTRODUCTION
PYTHON supports 3 logical operators:
1. AND
2. OR
3. NOT
LOGICAL AND OPERATOR:
LOGICAL AND OPERATOR returns TRUE if both the values are TRUE. Otherwise returns FALSE.
# Logical and operator example
a = True
b = False
print("\nValue of a ->", a)
print("\nValue of b ->", b)
print("\nValue of a and b ->", a and b)
PYTHON LOGICAL OPERATORS : Output
Value of a -> True
Value of b -> False
Value of a and b -> False
# Logical and operator example
a = True
b = True
print("\nValue of a ->", a)
print("\nValue of b ->", b)
print("\nValue of a and b ->", a and b)
PYTHON LOGICAL OPERATORS : Output
Value of a -> True
Value of b -> True
Value of a and b -> True
# Logical and operator example
a = False
b = False
print("\nValue of a ->", a)
print("\nValue of b ->", b)
print("\nValue of a and b ->", a and b)
PYTHON LOGICAL OPERATORS : Output
Value of a -> False
Value of b -> False
Value of a and b -> False
LOGICAL OR OPERATOR:
LOGICAL AND OPERATOR returns TRUE if any of the value is TRUE. If both the values are FALSE then returns FALSE.
# Logical or operator example
a = False
b = True
print("\nValue of a ->", a)
print("\nValue of b ->", b)
print("\nValue of a or b ->", a or b)
PYTHON LOGICAL OPERATORS : Output
Value of a -> False
Value of b -> True
Value of a or b -> True
# Logical or operator example
a = True
b = True
print("\nValue of a ->", a)
print("\nValue of b ->", b)
print("\nValue of a or b ->", a or b)
PYTHON LOGICAL OPERATORS : Output
Value of a -> True
Value of b -> True
Value of a or b -> True
# Logical or operator example
a = False
b = False
print("\nValue of a ->", a)
print("\nValue of b ->", b)
print("\nValue of a or b ->", a or b)
PYTHON LOGICAL OPERATORS : Output
Value of a -> False
Value of b -> False
Value of a or b -> False
LOGICAL NOT OPERATOR:
LOGICAL NOT OPERATOR returns the opposite of any expression. If any expression is TRUE then returns FALSE and vice versa.
# Logical not operator example
a = True
b = False
print("\nValue of a ->", a)
print("\nValue of b ->", b)
print("\nValue of not a ->", not a)
print("\nValue of not b ->", not b)

RELATED TOPICS:
Pingback: PYTHON MEMBERSHIP OPERATORS - Sayantan's Blog On Python Programming