Question About Logic In Python

Steven D'Aprano steve at REMOVETHIScyber.com.au
Tue Sep 20 19:03:00 EDT 2005


On Tue, 20 Sep 2005 03:03:15 +0000, Ron Adam wrote:

> Steven D'Aprano wrote:
>> Are there actually any usage cases for *needing* a Boolean value? Any
>> object can be used for truth testing, eg:

[snip]

> Of course if any of the default False or True conditions are 
> inconsistent with the logic you use, you need to do explicit truth testing.

[snip]

> So..
> 
>     bool(a and b) * value
> 
> Would return value or zero, which is usually what I want when I do this 
> type of expression.

That's all very interesting, and valuable advice for somebody who doesn't
understand how Python's logical operators work, but the question is, when
would you actually want that type of expression?

In practice, how often do you really care that your truth values have the
specific values 0 and 1 rather than anything false and anything true? In
what circumstances?



-- 
Steven.




More information about the Python-list mailing list