Is comparing two characters (that is one character str) in Python (3.x if that matters) well defined?
or do I have to make an explicit conversion?
In other words, is:
'a' > 'b'
the same as:
ord('a') > ord('b')
When not sure, check the docs:
Strings (instances of
str) compare lexicographically using the numerical Unicode code points (the result of the built-in functionord()) of their characters.
So yes, the behavior is well defined.
ń precedes letter ó, however in Python 'ń'<'ó' is False, because ord('ń') is 324 and ord('ó') is 243. Similarly 'å' < 'ä' is False even though in Swedish å precedes ä.
memcmp. That is pretty well-defined. It indeed uses the literal character codes. (And while typing this, a question arises. What else would you expect?)'a' > 'b'is a lexicographic comparison, andord('a') > ord('b')is a numerical comparison. I'm unsure if this makes a difference when only 1 character is used.