Prahlad Inala
Prahlad Inala

Follow

Prahlad Inala

Follow
Comparison Operators in Python

Comparison Operators in Python

Prahlad Inala's photo
Prahlad Inala
ยทJul 11, 2021ยท

1 min read

Play this article

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
ย 
Share this