Python 3 – Learn it quick – Comparison Operators
In this lesson, we are learning about comparison operators. In Python, the below comparison operators are supported,
1. Equal to
2. Not Equal To or Different
3. Higher than
4. Lower than
5. Higher than or equal to
6. Lower than or equal to
Operator Name | Symbol | Sample Operation | Description |
---|---|---|---|
Equal To | "==" | 5==5.0, ‘str1’ == ‘str1’ | If two operands are equal, then the condition is true |
Not Equal To or Different | != | 3 != 4 | If two operands are not equal, then the condition is true |
Higher than | > | 8 > 6 | If Operand A is greater than operand B, then the condition is true |
Lower than | < | 3 < 37 | If operand A is less than operand B, then the condition is true |
Higher than or equal to | >= | 6 >= 6 | If the operand A is greater than or equal to the operand B, then the condition is true |
Lower than or equal to | <= | 4 <= 5 | If the operand A is less than or equal to operand B, then condition is true |
Equal to
x = 55
y = 55
if x == y:
print("x is equal to y...")
else:
print("x is not equal to y...")
Not Equal To
x = 45
y = 55
if x == y:
print("x is equal to y...")
else:
print("x is not equal to y...")
Greater than
x = 76
y = 55
if x > y:
print("x is greater than y...")
print("Print the value of x :", x)
else:
print("x is not greater than y...")
Greater than or equal to
x = 76
y = 55
if x >= y:
print("x is greater than or equal to y...")
print("Print the value of x :", x)
else:
print("x is not greater than or equal to y...")
Less than
x = 76
y = 55
if x < y:
print("x is less than y...")
print("Print the value of x :", x)
else:
print("y is less than x...")
print("Print the value of y :", y)
Less than or equal to
x = 76
y = 55
if x <= y:
print("x is less than or equal to y...")
print("Print the value of x :", x)
else:
print("y is less than or equal to x...")
print("Print the value of y :", y)