Question About Logic In Python

Terry Hancock hancock at anansispaceworks.com
Thu Sep 22 18:08:17 EDT 2005


On Thursday 22 September 2005 12:26 pm, Ron Adam wrote:
> Steve Holden wrote:
> > Ron Adam wrote:
> >>  >>> True * True
> >> 1                   # Why not return True here as well?
> >>
> > Why not return 42? Why not return a picture of a banana?
> 
> My question still stands.  Could it be helpful if bools were preserved 
> in more cases than they are now?

No.  "*" is "multiplication".
The multiplication operator is undefined for boolean values. It only
makes sense if they are interpreted as numbers. As it happens, both
can be coerced to 1, so the result is 1*1. This makes perfect sense
to me.

>>> True and True
True

Also makes sense (and this is indeed what happens).

Cheers,
Terry

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




More information about the Python-list mailing list