Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python string comparison with different case and float

Tags:

python

why python is giving output like this:

>>> 'apple' > 'T'
True
>>> 'apple' > 't'
False

It should be True for both cases.right?

Edit:

I got the Idea of ASCII Table.Thanks!!

Now what about this.Is 11.1 is being treated as '11.1'?

>>> 'apple' > 11.1
True
like image 711
MBanerjee Avatar asked Dec 09 '22 20:12

MBanerjee


1 Answers

Because a comes after T in the ASCII character set, but before t.

The decimal ASCII encoding of these letters:

  • T is 84.
  • a is 97.
  • t is 116.
like image 88
cdhowie Avatar answered Dec 25 '22 03:12

cdhowie