A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from http://mail.python.org/pipermail/python-list/2005-September/342122.html below:

Question About Logic In Python

Question About Logic In PythonRon Adam rrr at ronadam.com
Thu Sep 22 20:09:21 EDT 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 
boolean math.

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
> 
> True
> 
> Also makes sense (and this is indeed what happens).

Only because True is the last value here. ;-)



> Cheers,
> Terry


Cheers,
Ron














More information about the Python-list mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4