Search code examples
pythonpython-2.7comparisonstring-comparisoncomparison-operators

How does Python order strings?


I've so far discovered that in Python:
[space] < 0-9 < A-Z < a-z
when ordering strings.

But why is it that '[space] a' < 'a'? 
And why is it that 'abc' > 'ABCDEFG'?

How are strings ordered in Python?
Is there a flowchart that will help me understand this process?


Solution

  • Strings of the same type are ordered naively, with lower byte values or code points ordered before higher byte values or code points.