Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
Comparison operators are used to determine equality of two data values between members of the same type. These comparison operators are supported for all built-in types. Comparisons yield true or false values, based on the validity of the comparison expression. Python chooses to interpret these values as the plain integers 0 and 1 for false and true, respectively, meaning that each comparison will result in one of those two possible values. A list of Python's value comparison operators is given in Table 4.1.
| operator | function |
|---|---|
| expr1 < expr2 | expr1 is less than expr2 |
| expr1 > expr2 | expr1 is greater than expr2 |
| expr1 <= expr2 | expr1 is less than or equal to expr2 |
| expr1 >= expr2 | expr1 is greater than or equal to expr2 |
| expr1 == expr2 | expr1 is equal to expr2 |
| expr1 != expr2 | expr1 is not equal to expr2 (C-style) |
| expr1 <> expr2 | expr1 is not equal to expr2 (ABC/Pascal-style)[a] |
[a] This “not equals” sign will slowly be phased out. Use != instead.