Krivalar Tutorials
Krivalar Tutorials

# Python - Comparison Operators

## What is Comparison Operators (or) Relational Operators

Comparison operators are used to compare the value of two operands and return the result as a Boolean value( either True or False). Comparison operators are also known as Relational Operators. The relational operators describe the relationship between the left and right operands.

Following are the Relational operators in the python.

SnoOperators Meaning Example
1 (==)is equal to Returns true only if both two operands are equal >>> a=10
>>>b=12
>>>(a==b)
False
2 (!=) is not equal Rreturns true if the value on left side is not equal to the value on right side >>>a=50
>>>b=19
>>>(a!=b)
True
3 (<) is less than Return true only if the value on left side is less than value on right side >>>a=5
>>>b=10
>>>(a < b)
True
4 (>) is greater than Return true only if the value on lift side is greater than the value on right side >>>a=20
>>>b=10
>>>(a>b)
>>>True
5 (<=) is less than or equal Return true only if the value on left side is less than or equal to the value on right side >>>a=15
>>>b=20
>>>(a<=b)
True
6 (>=) is greater than or equal to Return true only if the value on lift side is greater than or equal to the value on right side >>>a=10
>>>b=15
>>>(a>=b)
False

## Example Program with all Comparison Operators

```>> a=20
>> b=15
>> # shows how to use (==) operator
>> print(a==b)
False
>> # shows how to use the (!=) operator
>> print(a!=b)
True
>> # shows how to use the (<) operator
>> print(a<b)
False
>> # shows how to use the (>) operator
>> print(a>b)
True
>> # shows how to use the (>=) operator
>> print(a>=b)
True
>> # shows how to use the (<=) operator
>> print(a<=b)
False```