- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to 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
Advertisements