<1> compare (that is, relational) operators
The comparison operators in Python are the following table
operator |
Description |
Example |
== |
Checks whether the values of the two operands are equal, and if so, the condition becomes true. |
If a=3,b=3 (a = = B) is true. |
!= |
Checks whether the values of the two operands are equal, and if the values are not equal, the condition becomes true. |
True if a=1,b=3 (a! = b). |
<> |
Checks whether the values of the two operands are equal, and if the values are not equal, the condition becomes true. |
True if A=1,b=3 (a <> b). This is similar to! = operator |
> |
Checks if the value of the left operand is greater than the value of the right operand, and if so, the condition is true. |
True if A=7,b=3 (a > B). |
< |
Checks if the value of the left operand is less than the value of the right operand, and if so, the condition is true. |
If A=7,b=3 (a < b) is false. |
>= |
Checks whether the value of the left operand is greater than or equal to the value of the right operand, and if so, the condition is true. |
True if A=3,b=3 (a >= b). |
<= |
Checks whether the value of the left operand is less than or equal to the value of the right operand, and if so, the condition is true. |
True if A=3,b=3 (a <= b). |
<2> logical operators
operator |
Logical Expressions |
Description |
Example |
and |
X and Y |
Boolean "and"-if x is False,x and y returns FALSE, otherwise it returns the computed value of Y. |
(A and B) returns 20. |
Or |
X or Y |
Boolean "or"-if x is true, it returns true, otherwise it returns the computed value of Y. |
(A or B) returns 10. |
Not |
Not X |
Boolean "Non"-returns False if X is True. If X is False, it returns TRUE. |
Not (A and B) returns False |
Python comparison operators and logical operators