Relational operators in Python
Using relational operators we can compare the two items or operands.
Python has the following relational operators.
Operator | Operation |
---|---|
== | 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
Post a Comment
If you have any query, feel free to ask.