RELATIONAL OPERATOR IN PYTHON

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))

OUTPUT:
False
True
True

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  itsaihub@gmail.com . See your articles appearing on AI HUB platform and help other AI Enthusiast.

About Diwas

🚀 I'm Diwas Pandey, a Computer Engineer with an unyielding passion for Artificial Intelligence, currently pursuing a Master's in Computer Science at Washington State University, USA. As a dedicated blogger at AIHUBPROJECTS.COM, I share insights into the cutting-edge developments in AI, and as a Freelancer, I leverage my technical expertise to craft innovative solutions. Join me in bridging the gap between technology and healthcare as we shape a brighter future together! 🌍🤖🔬

View all posts by Diwas →

3 Comments on “RELATIONAL OPERATOR IN PYTHON”

Leave a Reply

Your email address will not be published. Required fields are marked *