How to compare numbers in Python?

PythonProgramming

You can use relational operators in python to compare numbers(both float and int) in python. These operators compare the values on either side of them and decide the relation among them. Assume variable a holds 10 and variable b holds 20, then

Operator
Example
==
(a == b) is not true.
!=
(a != b) is true.
>
(a > b) is not true.
<
(a < b) is true.
>=
(a >= b) is not true.
<=
(a <= b) is true.

Example

You can use this as follows −

a = 10
b = 20
print(a == b)
print(a != b)
print(a > b)
print(a < b)
print(a >= b)
print(a <= b)

Output

This will give the output −

False
True
False
True
False
True
raja
Published on 20-Apr-2018 11:37:27
Advertisements