1.

Program Flow Control in Python

Answer»

Relational Operators in Python

The Table gives a list of relational operators available in Python along with their functions:

OperatorWhat it does
==Is equal to
>=Is Greater than or Equal to
<=Is Less than or Equal to
>Is Greater than
<Is Less than
!=Not Equal to

Some examples are given below:

# Equality Operator
>>> 10 == 10
True # 10 is equal to 10, so true
>>> 10 == "10"
False # The first string is of type int, 2nd of type string, so false.
# Greater than
>>> 10 > 20
False # 10 is lesser than 20, so above expression is false.
# Inequality
>>> 10 != 20
True # 10 is not equal to 20, so the expression is true
# Greater than or equal to
>>> (2 + 3) >= (4 + 1)
True # (2 + 3) = 5 and (4 + 1) = 5, so the expression is true.

Note: Never use relational operators to compare boolean operations. Use is or is not operators for it.

>>> True is False
False
>>> True is not False
True


Discussion

No Comment Found