Logical Operator#

Logical assignment performs a logical operation between two operands and return the boolean result

Operation

Operator

Definition

Logical AND

and

Assign True only if both operands are valid

Logical OR

or

Assign True if at least one of the operands is valid

Logical NOT

not

Assign True if the operand is not valid

Examples

# logical AND
a = 1
b = 2
logical_and = (a == 1) and (b == 2)
print(logical_and)        # True
True
# logical OR
a = 1
b = 2
# logical OR
print(True or False)     # True
logical_or = (a == 10) or (b == 2)
print(logical_and)        # True
True
True
# logical NOT
print(not True)          # False
logical_not = not (a == 10)
print(logical_not)        # True
False
True