In this python tutorial, we will discuss python comparison operators. We will also check:
- What is comparison operators in python
- What does != mean in python
- What does == mean in python
- What does > mean in python
- What does < mean in python
- What does >= mean in python
- What does <= mean in python
What is comparison operators in python
A comparison operator in python also called the relational operator. It compares the values of two operands and returns True or False based on the condition is met. So, we have six comparison operators in python which include less than, greater than, less than or equal to, greater than or equal to, equal to, and not equal to.
So, Let’s understand all one by one.
What does != mean in python
Python not equal is denoted by (!=) operator and it returns True if the value on either side of the operator are unequal.
Example:
u = 10
v = 5
print(u != v)
After writing the above code (what does != mean in python), Once we will print then the output will appear as “ True ”. Here, u is not equal to v so it returns the output as True.
You can refer to the below screenshot what does != mean in python.
You may like Crosstab in Python Pandas.
What does == mean in python
Python equal to is denoted by (==) operator and it returns True if the value on either side of the operator is equal.
Example:
u = 5
v = '5'
print(u == v)
After writing the above code (what does == mean in python), Once we will print then the output will appear as “ False ”. Here, we can see that 5 is an integer and ‘5’ is a string that is unequal. So, it returns the output as False.
You can refer to the below screenshot what does == mean in python.
What does > mean in python
Let’s see what does (>) mean in comparison operator
In python, the greater than operator is denoted by (>). It checks whether the left value is greater than the one on the right side and if it is greater then it returns True.
Example:
u = 15
v = 10
print(u > v)
After writing the above code (what does > mean in python), Once we will print then the output will appear as “ True ”. Here, we can see that 15 is greater than 10. So, it returns the output as True.
You can refer to the below screenshot what does > mean in python.
Read How to Put Screen in Specific Spot in Python Pygame
What does < mean in python
Now, let’s see what does (<) mean in python.
In python, less than is denoted by (<) operator, it checks if the left value is less than that on the right or not. If the left value is less than the right value then it returns True.
Example:
u = 10
v = 12
print(u < v)
After writing the above code (what does < mean in python), Once we will print then the output will appear as “ True ”. Here, we can see that 10 is less than 12. So, it returns the output as True.
You can refer to the below screenshot what does < mean in python.
What does >= mean in python
The greater than or equal operator is denoted as (>=). This operator returns True only if the value on the left side is greater than or equal to that on the right then it returns True otherwise it will return False.
Example:
u = 15
v = 12
print(u >= v)
After writing the above code (what does >= mean in python), Once we will print then the output will appear as “ True ”. Here, we can see that 15 is greater or equal to 12. So, it returns the output as True.
You can refer to the below screenshot what does >= mean in python.
What does <= mean in python
The less than or equal to operator is denoted by (<=). It returns True only if the value on the left is either less than or equal to that on the right of the operator.
Example:
u = 12
v = 15
print(u <= v)
After writing the above code (what does <= mean in python), Once we will print then the output will appear as “ True ”. Here, we can see that 12 is less than or equal to15. So, it returns the output as True.
You can refer to the below screenshot what does <= mean in python.
You may like the following Python tutorials:
- Linked Lists in Python
- How to display calendar in Python
- How to make a calculator in Python
- Python Booleans
- Regular Expressions in Python
- Python print 2 decimal places
- Python generators (Python Generator vs Iterator)
- Python Counter – Detailed Tutorial
In this Python tutorial, we have learned about python comparison operators. Also, We covered these below topics:
- What is comparison operators in python
- What does != mean in python
- What does == mean in python
- What does > mean in python
- What does < mean in python
- What does >= mean in python
- What does <= mean in python
I am Bijay Kumar, a Microsoft MVP in SharePoint. Apart from SharePoint, I started working on Python, Machine learning, and artificial intelligence for the last 5 years. During this time I got expertise in various Python libraries also like Tkinter, Pandas, NumPy, Turtle, Django, Matplotlib, Tensorflow, Scipy, Scikit-Learn, etc… for various clients in the United States, Canada, the United Kingdom, Australia, New Zealand, etc. Check out my profile.