I just don't get it

John Hazen invalid at hazen.net
Sat Feb 28 01:33:40 CET 2004


* Eduardo Elgueta <eelgueta at navix.cl> [2004-02-27 16:18]:
> Hi All,
> 
> Would anyone be so kind to explain this?
> 
> -- begin --
> >>> (176L,) > 300
> True
> --end--

Comparing objects of different types (tuple and integer in your
example), while deterministic within a specific python version, puts
them in an arbitrary order.

>>> () > 300
True
>>> () > []
True
>>> [] > ()
False
>>> 'a' > 300
True
>>> 'a' > ()
False
>>> () > 'a' > 300
True
>>> [] > 'a'
False
>>> [] > 300
True
>>> () > 'a' > [] > 300
True


So, you probably don't want to be comparing disparate types and
attaching any meaning to the result.

If you wanted to compare the two numbers in your example, you would want
to index the tuple to get at the value inside it:

>>> (176L,) > 300
True
>>> (176L,)[0] > 300
False


HTH-

John
< my_first_name AT my_last_name DOT net >




More information about the Python-list mailing list