Comparison of strings and integer
Calvelo Daniel
dcalvelo at pharion.univ-lille2.fr
Tue Jul 25 15:11:24 EDT 2000
Remco Gerlich <scarblac-spamtrap at pino.selwerd.nl> wrote:
: Franz GEIGER wrote in comp.lang.python:
:> Still not very experienced in programming Python I recently compared
:> accidentially a string variable with an integer variable. Python did it his
:> way, which was not my way: I expected a conversion like Perl does or a
:> runtime error like REBOL does. Is there any way to prevent Python from doing
:> so?
:>
:> Python: print "1" > 1 --> 1
: Python's docs say that sorting order for incompatible types is
: arbitrary but consistent. Or so I seem to remember, can't find it at
: the moment.
>From the tutorial, section 5.6 (as of 1.5.2):
"""
Note that comparing objects of different types is legal. The outcome
is deterministic but arbitrary: the types are ordered by their name.
Thus, a list is always smaller than a string, a string is always
smaller than a tuple, etc. Mixed numeric types are compared according
to their numeric value, so 0 equals 0.0, etc.
"""
-- Daniel Calvelo Aros
calvelo at lifl.fr
More information about the Python-list
mailing list