1
print(4 > 5)

output is False this is very easy to understand using basic math

print("a" > "A")

output is True

how does python compare a and A ?

eyllanesc
  • 235,170
  • 19
  • 170
  • 241

2 Answers2

7

Python string comparison is performed using the characters in both strings. The characters in both strings are compared one by one. When different characters are found then their Unicode value is compared. The character with lower Unicode value is considered to be smaller.

The Unicode value of 'A' is 65, whereas the for 'a' it is 97.

The ord() function returns the Unicode value of a character.

ord('A')  # returns 65
ord('a')  # returns 97
ord('AA')  # ERROR: ord() expects a string of length 1.
aydee45
  • 516
  • 3
  • 14
0

"a" ascii is 97 --> ord("a")

"A" ascii is 65 --> ord("A")

Hence:

print("a" > "A") --> True
David Meu
  • 1,527
  • 9
  • 14