Why is 'a' greater than 'A' in python?

Question:

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?

Asked By: Bhurtel Maheshwor

||

Answers:

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

Answered By: Sadra

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

Answered By: Sandeep Vokkareni

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

>>> ord('a')
97
>>> ord('A')
65
Answered By: user12690225

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

Answered By: shamnad sherief
Categories: questions Tags:
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.