Search code examples
pythonpython-3.xmaxalphabet

How python choose the max letters from string


Please tell me why python choose this:

print(max("NEW new"))

OUTPUT: w

Had i understood correctly: lowercase in python on the first place, on the second place uppercase?

Thanks!


Solution

  • max will compare the ASCII value of each character in the string. You can see for yourself what they are by trying out ord('N') or ord(' ') or ord('w')

    here is the result from python interpreter

    >>> string = "NEW new"
    >>> for s in string:
    ...     print(s , "--", ord(s))
    ... 
    N -- 78
    E -- 69
    W -- 87
      -- 32
    n -- 110
    e -- 101
    w -- 119
    >>>