Comparison Operators
Explore Python's comparison operators and identity operators to understand how they compare values and memory locations. Learn about boolean outcomes, the concept of integer interning, and why floating-point comparisons require special consideration due to binary representation limits.
We'll cover the following...
Comparison operators can be used to compare values in mathematical terms. The precedence of comparison operator is same.
Symbol | Operator |
| Greater Than |
| Less Than |
| Greater Than or Equal To |
| Less Than or Equal To |
| Equal To |
| Not Equal To |
Output of comparison operators
The result of a comparison is always a bool. If the comparison is correct, the value of the bool will be True. Otherwise, its value will be False.
Try it yourself
Let’s look at a few examples. Our AI Mentor can explain the code as well.
Identity operators
In Python, the is and is not operators are used to compare the memory ...