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.
Hi to all, how is all, I think every one is getting more from this web page, and your views are good in favor of new visitors.
This post provides clear idea designed for the new users of blogging, that actually
how to do blogging and site-building.