print('a'>'b') Returns False similar to this print('a'>'A') Returns True
Asked
Active
Viewed 3,061 times
-3
-
Python is comparing the Unicode value of each char. 'a' = 61, 'b' = 62, and 'A' = 41. – TruBlu Nov 09 '19 at 14:25
2 Answers
3
Python uses Lexicographical ordering for strings. This means that it uses the Unicode point number to order characters.
Reference: https://docs.python.org/3/tutorial/datastructures.html#comparing-sequences-and-other-types
You may find this useful: https://en.wikipedia.org/wiki/List_of_Unicode_characters
Sxribe
- 779
- 5
- 16
-1
Python 3 uses unicode
Each character has a value according to the ASCII table:
https://www.cs.cmu.edu/~pattis/15-1XX/common/handouts/ascii.html
'a' = 97
'b' = 98
'A' = 65
Which is why 97 > 98 returns false
Almog
- 19
- 4
-
This is incorrect. Python uses Lexicographical ordering (Unicode), not ASCII. Check my answer. – Sxribe Nov 09 '19 at 15:25
-
-