Compare Numbers in Python



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
Updated on: 2020-03-05T10:48:16+05:30

17K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements