question about True values

Antoon Pardon apardon at forel.vub.ac.be
Fri Oct 27 11:16:57 CEST 2006


On 2006-10-26, Steven D'Aprano <steve at REMOVE.THIS.cybersource.com.au> wrote:
> On Wed, 25 Oct 2006 19:19:59 +0000, John Salerno wrote:
>
>> Oh!!! I get it now! I was thinking that
>> 
>> if s
>> 
>> was the same as
>> 
>> if s == True
>
> No. But you know that now :)
>
>> because I know sometimes you can write if statements this way (though 
>> it's wordy). 
>
> You can, but shouldn't.
>
>
>> But what I didn't realize was that in the cases I was 
>> thinking of, 's' was an expression that evaluated to a boolean value, 
>> not an actual value of some other type!
>> 
>> So I suppose
>> 
>> if (10 > 5)
>
> Is the same as:
>
> if True
>
> because (10 > 5) evaluates as True.
>
>  
>> would be the same as
>> 
>> if (10 > 5) == True
>
> Did you mean
>
> if (10 > 5) == True == True
>
> or 
>
> if (10 > 5) == True == True == True
>
> or even 
>
> if (10 > 5) == True == True == True == True
>
> I hope you see my point now.
>
>
>> because (10 > 5) does evaluate to "True".
>
> I think it is a good time to remind people of some extremely well-thought
> out opposition to the introduction of bools to Python from Laura Creighton:
>
> http://mail.python.org/pipermail/python-list/2002-April/095878.html
>
> She lost the debate, Guido had the final word and Python now has bools.
> Take particular note of her description of Python distinguishing between
> Something ("cat", 4, [0, 1, 2] etc) and Nothing ("", 0, [] etc).

Yes and IMO that is a less usefull distinction than the distinction
between True and False. When I write code I think in terms of
conditions. In those conditions this has to be treated this way
otherwise it has to be treated an other way. Conditions give
results that are either True or False, not Something or Nothing.
I don't think of 10 > 5 as Something while 5 < 10 would be
Nothing. So while the paradigma of the language may be the
distinction of Something vs Nothing the programmer will often
enough think in terms of True and False. So IMO it would have
been better if python had made the distinction between True and
False and so made the programmer code the Something/Nothing
disctinction explicitly.

-- 
Antoon Pardon



More information about the Python-list mailing list