Logical Operator in Python

Logical Operator in Python



OperatorDescription
or
If any one of the operand is true, then the condition becomes true.
and
If both the operands are true, then the condition becomes true.
not
Reverses the state of operand/condition.

Example  To test Logical Operators:


#Demo Program to test Logical Operators
a=int (input("Enter a Value for A:"))
b=int (input("Enter a Value for B:"))
print ("A = ",a, " and b = ",b)
print ("The a > b or a == b = ",a>b or a==b)
print ("The a > b and a == b = ",a>b and a==b)
print ("The not a > b = ",not a>b)
#Program End


Example Result:


Enter a Value for A:50

Enter a Value for B:40

A = 50 and b = 40

The a > b or a == b = True

The a > b and a == b = False

The not a > b = False