Python Free Tutorial

Comparison operators, are used to compare two values of two operands present in either side of operator, return boolean value True of False. These comparison operators can be combined with the arithmetic and bitwise operators. They are also called Relational operator in python. The comparison operations are listed in the following table:

Operator  Name                        Example
==        Equal                       x == y 
!=        Not equal                   x != y 
>         Greater than                x > y 
<         Less than                   x < y 
>=        Greater than or equal to    x >= y 
<=        Less than or equal to       x<=y
<>        Not equal                   x<>y

When working with Boolean values, Python provides operators to combine the values using the standard concepts of “and”, “or”, and “not”. These sorts of Boolean operations will become extremely useful when we begin discussing control flow statements such as conditionals and loops.

>>> a = 5
>>> b = 9
>>> c = 8
>>> print (a>b)
>>> print (b>c)
>>> print ( (a>b) or (b>c))


Here, on the fifth sixth line we are doing logical operation ‘or’ on the value boolean of (a>b) and (b>c). Boolean of False or True gives the output True. Hence the output of sixth line is True. This much for relational operator in python. We will catch you in next tutorial.

This page is contributed by Diwas & Sunil . If you like AIHUB and would like to contribute, you can also write an article & mail your article to . See your articles appearing on AI HUB platform and help other AI Enthusiast.

About Diwas Pandey

Highly motivated, strong drive with excellent interpersonal, communication, and team-building skills. Motivated to learn, grow and excel in Data Science, Artificial Intelligence, SEO & Digital Marketing

View all posts by Diwas Pandey →


Leave a Reply

Your email address will not be published.