May 2019
Beginner
528 pages
29h 51m
English
Strings may be compared with the comparison operators. Recall that strings are compared based on their underlying integer numeric values. So uppercase letters compare as less than lowercase letters because uppercase letters have lower integer values. For example, 'A' is 65 and 'a' is 97. You’ve seen that you can check character codes with ord:
In [1]: print(f'A: {ord("A")}; a: {ord("a")}')A: 65; a: 97
Let’s compare the strings 'Orange' and 'orange' using the comparison operators:
In [2]: 'Orange' == 'orange'Out[2]: FalseIn [3]: 'Orange' != 'orange'Out[3]: TrueIn [4]: 'Orange' < 'orange'Out[4]: TrueIn [5]: 'Orange' <= 'orange'Out[5]: TrueIn [6]: 'Orange' > 'orange'Out[6]: FalseIn [7]: 'Orange' ...
Read now
Unlock full access