Comparison Operators in Python

Comparison Operators in Python

ยท

1 min read

What are Comparison Operators in Python?

Comparison operators are used to comparing different values in python. Comparison operators evaluate to a boolean value,i.e,True (or) False.

Following are the comparison operators in python:

  1. ==
  2. !=
  3. >
  4. <
  5. >=
  6. <=

== Operator

x = 5
y = 3
print(x == y)
#False
# returns False because 5 is not equal to 3

!= Operator

x = 5
y = 3
print(x != y)
#True
# returns True because 5 is not equal to 3

> Operator

x = 5
y = 3
print(x > y)
#True
# returns True because 5 is greater than 3

< Operator

x = 5
y = 3
print(x < y)
#False
# returns False because 5 is not less than 3

>= Operator

x = 5
y = 3
print(x >= y)
#True
# returns True because five is greater, or equal, to 3

<= Operator

x = 5
y = 3
print(x <= y)
#False
# returns False because 5 is neither less than or equal to 3
ย