[Tutor] True and 1 [was Re: use of the newer dict types]
Alan Gauld
alan.gauld at btinternet.com
Sun Jul 28 10:07:54 CEST 2013
On 28/07/13 05:04, Steven D'Aprano wrote:
> On 28/07/13 09:53, Alan Gauld wrote:
>
>> Its not that false propagates out, it's how Python does a comparison
...
>> comparison operations return -1, 0 or 1.
>
> You're thinking of the cmp() builtin
I was trying to use that for simplicity. (Although given Jim's penchant
for understanding the inner workings, that was probably a mistake!)
The real point I was trying to make was that the equality test does not
work by comparing the boolean value of the expressions on each side but
by applying comparisons to the actual values (so for lists it checks
length and item values). By overloading the comparison operators the
test rules are effectively arbitrary for any given class. The boolean
result is then applied at the very end based on the test outcome.
> Comparison operators haven't depended on cmp() for a long time. You can
> google "rich comparison operators" for more info:
>
> https://duckduckgo.com/?q=rich%20comparison%20operators
I only read the first two but one question remains:
If cmp() is gone is __cmp__() still supported? I'm assuming it
must be for backward compatibility?
--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
More information about the Tutor
mailing list