On Tue, Apr 19, 2011 at 7:09 AM, Christian Heimes <li...@cheimes.de> wrote:
> Am 18.04.2011 21:58, schrieb John Nagle:
>>     This is typical for languages which backed into a "bool" type,
>> rather than having one designed in.  The usual result is a boolean
>> type with numerical semantics, like
>>
>>  >>> True + True
>> 2
>
> I find the behavior rather useful. It allows multi-xor tests like:
>
> if a + b + c + d != 1:
>    raise ValueError("Exactly one of a, b, c or d must be true.")
>

Unless you're sure all of a, b, c, and d are boolean values, an int
with a negative value slipping in could result in the sum equaling 1,
but more than one of the variables evaluating to True in boolean
contexts.

-- 
regards,
kushal
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to