September 2026
1051 pages
35h 4m
English
In addition to arithmetic operators, there’s a second set of operators that allow comparing values such as numbers:
>>> 3 < 4True
Here we test if 3 is smaller than 4. The interpreter responds to such comparisons with a truth value—that is, True or False. A comparison is performed using a relational operator—in this case, <.
Table 3.1 contains a list of the relational operators.
|
Comparison |
Meaning |
|---|---|
|
3 == 4 |
Is 3 equal to 4? Note the double equal sign that distinguishes the comparison from an assignment. |
|
3 != 4 |
Is 3 different from 4? |
|
3 < 4 |
Is 3 less than 4? |
|
3 > 4 |
Is 3 greater than 4? |
|
3 <= 4 |
Is 3 less than or equal to 4? |
|
3 >= 4 |
Is 3 greater than or equal to 4? |
Table 3.1 ...
Read now
Unlock full access