comparing strings and integers

beliavsky at aol.com beliavsky at aol.com
Wed May 19 17:26:59 EDT 2004


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