Articles → Python → Comparison Operator In Python

Comparison Operator In Python






Comparison Operators




  1. Equals operator (==) → If the value of the left-hand side is equal to the value of right-hand side then returns true else false.
  2. Not equals (!=) → If the value of the left-hand side is not equal to the value of right-hand side then returns true else false.
  3. Greater than (>) → If the value of the left-hand side is greater than the value of right-hand side then returns true else false.
  4. Less than (<) → If the value of the left-hand side is less than the value of right-hand side then returns true else false.
  5. Greater than and equals to (>=) → If the value of the left-hand side is greater than or equal to the value of right-hand side then returns true else false.
  6. Less than and equals to (<=) → If the value of the left-hand side is less than or equal to the value of right-hand side then returns true else false.

Example




a = 5
b = 6

#conditonal operators
print(a==b) # returns false
print(a!=b) # returns true
print(a>b) # returns false
print(a<b) # returns true
print(a>=b) # returns false
print(a<=b)# returns true




Picture showing the output of the comparison operator in python

Click to Enlarge


Posted By  -  Karan Gupta
 
Posted On  -  Sunday, February 17, 2019

Query/Feedback


Your Email Id  
 
Subject 
 
Query/FeedbackCharacters remaining 250