Comparison Operators
In programming comparison operators are used to compare two or more values. These are comparison operators used in Python.
- Equals To – “==”
To check whether one value is equal to other value. The answer is returned in Boolean format.
Example:
>>> name = “Mohit” # Assignment
>>> name == “Mohit” # Comparison
True # Output
>>> x = 5 # Assigment
>>> 5 == x # Comparsion – LHS is equal to RHS here
True
*Use of If Condition
Syntax of if
if(condition):
statement
Example
>>> name = “Ramesh”
>>> if(name == “Ramesh”):
#indentation block
print(“Welcome Ramesh Babu”)
Welcome Ramesh Babu #output
- Greater than: “ > “
>>> x = 67
>>> if(x > 65):
print(x, ” is greater than 65″)
67 is greater than 65
Example with With if and else :
x = 68
if(x > 65):
print(x , ” is g t 65 “)
else:
print(x , ” is ngt 65 “)
# 68 is g t 65
- Greater than or equal to
Example :
>>> t = 678 # assignment
>>> t >= 789 # comparison
False # output
>>> t >= 678
True
>>> t >= 677
True
- Less Than
>>> cb = 56
>>> cb < 45
False
- Less than or equal to
>>> cb = 56
>>> cb <= 56
True
>>> cb <= 78
True

Ankit Srivastava is an IT trainer, technology educator, and digital skills mentor with expertise in programming, data analytics, AI, and software development. He has successfully trained thousands of learners, with more than 10,000 student enrollments on Udemy. His practical teaching approach empowers students and professionals to build in-demand technical skills. Colorstech channel where Ankit posts video tutorials has more than 8000 Subscribers.


