Question About Logic In Python
rrr at ronadam.com
Fri Sep 23 02:09:21 CEST 2005
Terry Hancock wrote:
> 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.
I'm not implying it doesn't make sense. It does to me as well. And it
would only make sense to return bools in this case if Python supported
If it did, coercion to ints (or floats) would still occur with mixed
types are used in expressions, but there are some situations where the
bool-bool results differ, so it's most likely an all or nothing move.
Both views are valid and there are benefits to both as well.
>>>>True and True
> Also makes sense (and this is indeed what happens).
Only because True is the last value here. ;-)
More information about the Python-list