Relational operators in Python

Relational operators in Python

Using relational operators we can compare the two items or operands.


Python has the following relational operators.


OperatorOperation
==Equal
!= Not equal
>Greater than
<Less than
>=Greater than or equal to
<=Less than or equal to


Equal - relational operator

To check whether the two operands are equal , '==' operation is performed.


Program

>>> 5 == 6
False
>>> 5 == 5
True


Not Equal - relational operator

To check whether the two operands are not equal to each other, '!=' operation is performed.


Program

>>> 5 != 6
True
>>> 5 != 5
False


Greater than - relational operator

To check whether the first operand is greater than second operand, '>' operation is performed.


Program

>>> 5 > 6
False
>>> 6 > 5
True

Less than - relational operator

To check whether the first operand is less than second operand, '<' operation is performed.


Program
>>> 5 < 6
True
>>> 6 < 5
False


Greater than or equal to - relational operator

To check whether the first operand is greater than or equal to the second operand, '>=' operation is performed.

Program

>>> 5 >= 6
False
>>> 6 >= 5
True
>>> 6 >= 6
True


Less than or equal to - relational operator

To check whether the first operand is less than or equal to the second operand, '<=' operation is performed.


Program

>>> 5 <= 6
True
>>> 6 <= 5
False
>>> 6 <= 6
True







Conclusion

With relational operators we can compare the two items or operands. 

Less than, greater than, is equal to, is not equal to, less than or equal to and greater than or equal to are the relational operators.






Previous                          Next

If you have any query, feel free to ask.

Post a Comment

If you have any query, feel free to ask.

Post a Comment (0)