Python Comparison Operators
Comparison Operators in Python.
To compare two or more variables or constants that have some values, a comparison operator is used. In six different ways, we can compare different variables or constants, compare whether two values are equal or if two values are not equal, and in several other ways.
Comparison Operators in Python
There are total 6 Comparison Operators in general:
1. Equal(==)
2. Not Equal(!=)
3. Greater than(>)
4. Less than (<)
5. Greater than equal to (>=)
6. Less than equal to(<=)
All comparison operators in python are discussed below in detail with their syntax and proper example:
1. Equal(==)
Syntax
Operand1 == Operand2
Example
>>> a = 10 >>> b = 20 >>> a == b False >>> 10 == 10 True >>> a == 10
True
2. Not Equal(!=)
Syntax
Operand1 != Operand2
Example
>>> a = 10 >>> b = 20 >>> a != b True >>> 10 != 10 False >>> a != 10
False
3. Greater than (>)
Syntax
Operand1 > Operand2
Example
>>> a = 10 >>> b = 20 >>> a > b False >>> 11 > 10 True >>> a > 15
False
4. Less than (<)
Syntax
Operand1 < Operand2
Example
>>> a = 10 >>> b = 20 >>> a < b True >>> 11 < 10 False >>> a < 15
True
5. Greater than equal to(>=)
Syntax
Operand1 >= Operand2
Example
>>> a = 10 >>> b = 20 >>> a >= b False >>> 11 >= 10 True >>> a >= 15
False
6. Less than equal to(<=)
Syntax
Operand1 <= Operand2
Example
>>> a = 10 >>> b = 20 >>> a <= b True >>> 10 <= 10 True >>> a <= 5
False
Prime Course Trailer
Related Banners
Get PrepInsta Prime & get Access to all 200+ courses offered by PrepInsta in One Subscription
Get over 200+ course One Subscription
Courses like AI/ML, Cloud Computing, Ethical Hacking, C, C++, Java, Python, DSA (All Languages), Competitive Coding (All Languages), TCS, Infosys, Wipro, Amazon, DBMS, SQL and others
Login/Signup to comment