Question About Logic In Python

Terry Hancock hancock at anansispaceworks.com
Fri Sep 23 09:13:44 EDT 2005


On Thursday 22 September 2005 07:09 pm, Ron Adam wrote:
> Terry Hancock wrote:
> > On Thursday 22 September 2005 12:26 pm, Ron Adam wrote:
> >>>>True and True
> > 
> > True
> > 
> > Also makes sense (and this is indeed what happens).
> 
> Only because True is the last value here. ;-)

Nope, works for False, too:

>>> True and False
False

I see what you mean, but if you were mixing types, then
you probably wanted the "value preserved" behavior. If
both objects are bool, the result is too (even if this
is only a coincidence, it still happens to be true).

So this still makes sense:

>>> True and 1
1

Effectively, what you'd be asking for is to have bool
coerce more strongly than ints or other types, so that
results would become boolean if any boolean argument
existed. But that would be a pretty major change in Python,
and break lots of code.



--
Terry Hancock ( hancock at anansispaceworks.com )
Anansi Spaceworks  http://www.anansispaceworks.com




More information about the Python-list mailing list