comparing strings and integers

David Stockwell winexpert at hotmail.com
Wed May 19 17:32:39 EDT 2004


without knowing any better, its possible "1" translates to 0x31 

so it would become 

0x31 > 1   ===>  True....

David
http://cellphone.duneram.com/index.html

----- Original Message ----- 
From: <beliavsky at aol.com>
Newsgroups: comp.lang.python
To: <python-list at python.org>
Sent: Wednesday, May 19, 2004 5:26 PM
Subject: comparing strings and integers


> By mistake I coded something like
> 
> print ("1" > 1)
> 
> and got the result "True". Comparing an integer and a string seems
> meaningless to me, and I would prefer to have an exception thrown. Can
> someone explain why Python allows comparisons between integers and
> strings, and how it handles those cases? Why is "1" > 1?
> 
> Pychecker does not warn about the line of code above -- I wish it did.
> 
> In my code what I really intended was to convert the "1" to an int and
> THEN do a comparison.




More information about the Python-list mailing list