Python Comparison Operators
What are operators and operands? Let’s explain with a simple example: 10 > 5. Here, 10 and 5 are the operands, and > is the operator.
Consider the variables a = 10 and b = 5.
| Operator | Description | Example | Result |
|---|---|---|---|
== | Checks if operand values are equal. If they are, the condition is true | a == b | False |
!= | Checks if operand values are not equal. If they are not equal, the condition is true | a != b | True |
> | Checks if the left operand is greater than the right operand. If it is, the condition is true | a > b | True |
< | Checks if the left operand is less than the right operand. If it is, the condition is true | a < b | False |
>= | Checks if the left operand is greater than or equal to the right operand. If it is, the condition is true | a >= b | True |
<= | Checks if the left operand is less than or equal to the right operand. If it is, the condition is true | a <= b | False |