Comparison Operators
Comparison Operators are used to compare the given two values/operands.
The following table presents to you all the Comparison Operators in Python, with a description, and an example.
| Operator Symbol | Description | Example |
|---|---|---|
| == | Equal to | x == y |
| != | Not Equal to | x != y |
| > | Greater than | x > y |
| < | Less than | x < y |
| >= | Greater than or equal to | x >= y |
| <= | Less than or equal to | x <= y |
Equal-To Operator
Equal-to Operator returns True if the given operands are equal in value, else it returns False.
In the following program, we shall find the output of Equal-to operator with unequal operand values.
Python Program
x, y = 5, 2
output = (x == y)
print(output)
Output
False
In the following program, we shall find the output of Equal-to operator with equal operand values.
Python Program
x, y = 8, 8
output = (x == y)
print(output)
Output
True
Not-Equal-To Operator
Not-Equal-To Operator returns True if the given operands are not equal in value, else it returns False.
In the following program, we shall find the output of Not-Equal-To operator with unequal operand values.
Python Program
x, y = 5, 2
output = (x != y)
print(output)
Output
True
In the following program, we shall find the output of Not-Equal-To operator with equal operand values.
Python Program
x, y = 8, 8
output = (x != y)
print(output)
Output
False
Greater-Than Operator
Greater-Than Operator returns True if the left operand is greater in value than that of right operand, else it returns False.
In the following program, we shall find the output of Greater-Than operator with left operand greater in value than that of right operand value.
Python Program
x, y = 5, 2
output = (x > y)
print(output)
Output
True
In the following program, we shall find the output of Greater-Than operator with left operand not greater in value than that of right operand value.
Python Program
x, y = 1, 8
output = (x > y)
print(output)
Output
False
Less-Than Operator
Less-Than Operator returns True if the left operand is lesser in value than that of right operand, else it returns False.
In the following program, we shall find the output of Less-Than operator with left operand lesser in value than that of right operand value.
Python Program
x, y = 1, 8
output = (x < y)
print(output)
Output
True
In the following program, we shall find the output of Less-Than operator with left operand not lesser in value than that of right operand value.
Python Program
x, y = 7, 3
output = (x < y)
print(output)
Output
False
Greater-Than-Or-Equal-To Operator
Greater-Than-Or-Equal-To Operator returns True if the left operand is greater or equal to in value with that of right operand, else it returns False.
In the following program, we shall find the output of Greater-Than-Or-Equal-To operator with left operand greater in value than that of right operand.
Python Program
x, y = 5, 2
output = (x >= y)
print(output)
Output
True
In the following program, we shall find the output of Greater-Than-Or-Equal-To operator with left operand equal in value with that of right operand.
Python Program
x, y = 8, 8
output = (x >= y)
print(output)
Output
True
In the following program, we shall find the output of Greater-Than-Or-Equal-To operator with left operand not greater in value with that of right operand.
Python Program
x, y = 4, 6
output = (x >= y)
print(output)
Output
False
