As a method:

def __lt__(self, other) 

compare strings?

    1 answer 1

    If you are interested in the principle of operation, then the comparison goes character by character ( in lexicographical order ). Those. The code of the first character of the first line is compared with the code of the first character of the second line. If it is less, it returns True , if it is more, it returns False , if it is equal, go to the next character.

    Algorithmically, it looks something like this:

     def __lt__(s1, s2): N = min(len(s1), len(s2)) for i in range(N): if ord(s1[i]) == ord(s2[i]): continue else: return ord(s1[i]) < ord(s2[i]) return len(s1) < len(s2) 

    If you are interested in the implementation, you will have to look into the Python sources.


    PS features of the letter ั‘ :

     > print('ะต' < 'ั') True > print('ั‘' < 'ั') False > print(ord('ั‘'), ord('ั')) 1105 1103 
    • one
      and what will return if the first line of the substring is the second? '12345' and '1234567' if verification only the first 5 characters check? Or is there another return down there? - Grundy
    • @Grundy, fair comment, thanks! - MaxU