0

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.

martineau
  • 119,623
  • 25
  • 170
  • 301

3 Answers3

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.

ASCII Table

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