Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is print('a' > 'b') False and print('a' > 'A') True?

When we execute the program print('a' > 'b') it gives us the answer False.

When we execute the program print('a' > 'A') it gives us the answer True.

Please help me with a detailed explanation.

like image 711
Ketan Avatar asked Oct 23 '25 15:10

Ketan


1 Answers

when comparing characters using the < or > it converts it to an integer.

according to ASCII Table

Meaning:

  • a is 97 decimal
  • b is 98 decimal
  • A is 65 decimal
  • B is 66 decimal

therefor:

print('a' > 'b') is false because print(97 > 98)

and then:

print('a' > 'A') is true because print(97 > 65)

like image 166
Dean Van Greunen Avatar answered Oct 26 '25 20:10

Dean Van Greunen



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!