Relational Operators Python

Relational operators are used to compare two variables.

It will return true , if the comparison or relation is true.

otherwise it will return false.




Example

Operator Description Example
== Checks both left and right operands are same 10 == 10 it will return true.
10 == 7 it will return false
!= Checks both left and right operands are not same. 10 != 20 it will return true.
10 != 10 it will return false.
< Checks whether the left operand is smaller than the right operand. 5 < 10 it will return true.
10 < 10 it will return false.
<= Checks whether the left operand is smaller than or equal to the right operand. 10 <= 10 it will return true
20 <= 10 it will return false.
> Checks whether the left operand is greater than the right operand. 50 > 10 it will return true
5 > 10 it will return false.
>= Checks whether the left operand is greater than or equal to the right operand. 10 >= 10 it will return true
5 >= 10 it will return false.



Relational Operators - Sample Program

Example

a = 5
b = 10

print(a == b)  #return False
print(a != b)  #return True
print(a < b)   #return True
print(a <= b)  #return True
print(a > b)   #return False
print(a >= b)  #return False

Relational operators are frequently used in decision making and looping statements. We will discuss about it in the future topics.