Home > database >  Why is 'a' greater than 'A' in python?
Why is 'a' greater than 'A' in python?

Time:02-26

First I tried this:

    print('a' > 'A')

The above statement returns true

Then I tried this:

    print('A' > 'a')

The above statement returns false

What is the reason?

CodePudding user response:

Because it has a higher unicode value. To check you can use:

>>> ord('a')
97
>>> ord('A')
65

CodePudding user response:

According to the ASCII table, value of 'A' is 65 and 'a' is 97.

So if u compare a single character between a-z,A-Z Python takes it's ASCII value.

You can check the ASCII table from here

CodePudding user response:

Checkout out ASCII table here. The comparison compares ASCII codes of a and A.

CodePudding user response:

In case of strings, Python compares the ASCII(American Standard Code of Information Interchange) values of the characters.

  • Related