Why is 'a'>'b' = False
and 'a'>'A' = True
in python?
anybody with a clear explanation of this.
I tried searching up, but couldn't really find an appropriate clear explanation.
Asked
Active
Viewed 86 times
0

martineau
- 119,623
- 25
- 170
- 301

speaking tree
- 11
- 5
-
3What are the values of `a`, `b`, and `A`? – Alexanderbira Jul 20 '20 at 17:27
-
The letter frmo the alphabet or variable that you set ? – azro Jul 20 '20 at 17:28
-
2I think OP means strings – Nicolas Gervais Jul 20 '20 at 17:28
-
1Maybe this helps: https://stackoverflow.com/questions/4806911/string-comparison-technique-used-by-python – Alexanderbira Jul 20 '20 at 17:30
-
In the ASCII character set, capital letters come first. So `'A'` has a lower character number than `'a'`. And obviously `'b'` comes after `'a'`. – John Gordon Jul 20 '20 at 17:32
3 Answers
5
Hello Welcome to Stack Overflow,
You mean:
'a' > 'b'
Out[3]: False
'a'>'A'
Out[4]: True
As this is based on the ascii values of 'a' = 97 and 'A' = 65. You can find the ascii values using ord()
function.
ord('a')
Out[7]: 97
ord('b')
Out[8]: 98
ord('A')
Out[9]: 65

AaravM4
- 380
- 1
- 4
- 21

user 923227
- 2,528
- 4
- 27
- 46
1
Take a look at the ASCII table and notice that uppercase letters are in the range 65-90 and lowercase letters are in the range 97-122. That's the default coding used for Python.

leo.barddal
- 118
- 5
1
You should learn about ASCII values. Click here to learn about ASCII value
Some char and their ASCII value is given below:
'a': 97
'b': 98
'A': 65
'B': 66.
so, when you are doing 'a'>'b' it means 97>98 which is False.
Similarly, when you are doing 'a'>'A' it means 97>65 which is True.

TheSohan
- 442
- 3
- 18