The key insight here is that string comparisons are not compared based on alphabetical order or any natural order, but instead in character order in ASCII. This order can be seen in the ASCII table.
Python will compare the first character on each line, and if it is the same, it will move on to the next. He will do this until the characters differ, or one line ends (in this case, a longer line will be considered larger).
As cdhowie pointed out, in ASCII decimal T is 84, a is 97, and T is 116. Therefore:
>>> 'T' < 'a' < 't' True
To show our second point:
>>> "apple" > "a" True
For a more natural comparison, see Does Python have a built-in function for naturally sorting strings?
To answer the question that you added in editing:
The simple answer is yes. Converts 11.1 to '11.1' .
A more complicated answer concerns how exactly the comparison is done in python. Python objects can be compared if they implement comparison comparison methods . In this link you can read information about the internal components of python.
As @glibdup pointed out, the above is incorrect. In python, different types are compared by the name of their type . So, since 'str' > 'float' any string will be larger than any float. Alternatively, any tuple will be larger than any row.
source share