question about True values

Georg Brandl g.brandl-nospam at gmx.net
Sat Oct 28 16:58:37 EDT 2006


J. Clifford Dyer wrote:
> Georg Brandl wrote:
>> J. Clifford Dyer wrote:
>> 
>>>  >>> (1 > 0) < 1
>>> False
>>>  >>> 1 > 0 < 1
>>> True
>>>  >>> 1 > (0 < 1)
>>> False
>>>  >>> 10 > (0 < 1)
>>> True
>> 
>> I hope you know why this works the way it does.
>> 
>> Georg
> 
> Yes, I do understand why it works.  I couldn't have crafted it if I 
> didn't, but my point is that the reason why it works is not explainable 
> if you believe that you are dealing with booleans.

Okay, but you should have left off the second example, because it has nothing
to do with the others.

>  It's only 
> explainable if you recognize that you are actually dealing with 
> integers, and specifically, 1 and 0.  So the something/nothing dichotomy 
> combined with an understanding of what the comparison operation REALLY 
> does (yield a 1 or a 0) helps you understand where your result came 
> from, while thinking in terms of true/false will mislead you.

That's true. The only sensible thing to do, if you had "real" booleans, for
1 > True, would be to raise an exception.

Georg



More information about the Python-list mailing list