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 SymbolDescriptionExample
==Equal tox == y
!=Not Equal tox != y
>Greater thanx > y
<Less thanx < y
>=Greater than or equal tox >= y
<=Less than or equal tox <= y
Python Comparison Operators

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)
Try Online

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)
Try Online

Output

True
ADVERTISEMENT

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)
Try Online

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)
Try Online

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)
Try Online

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)
Try Online

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)
Try Online

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)
Try Online

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)
Try Online

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)
Try Online

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)
Try Online

Output

False