On 23.06.2016 06:47, Lawrence D’Oliveiro wrote:
On Thursday, June 23, 2016 at 3:12:52 PM UTC+12, Larry Hudson wrote:
On 06/22/2016 12:42 AM, Lawrence D’Oliveiro wrote:
* boolean operators don’t have to operate on boolean values. The
   language spec
   <https://docs.python.org/3/reference/expressions.html#boolean-operations>
   says:

     “...the following values are interpreted as false: False, None, numeric
     zero of all types, and empty strings and containers (including strings,
     tuples, lists, dictionaries, sets and frozensets). All other values are
     interpreted as true.”

I feel that’s a needlessly complicated rule. It would have been simpler if
boolean operators (and conditional expressions like in if-statements and
while-statements) only allowed values of boolean types. But that’s one of
the few warts in the design of Python...
Wart??  I *strongly* disagree.  I find it one of the strengths of Python,
it enhances Python's expressiveness.
Tightening it up would rule out a whole class of common errors, from misunderstanding (or 
forgetting) the rule about what exactly gets interpreted as true and what as false 
<https://bugs.python.org/issue13936> 
<http://stackoverflow.com/questions/28116931/datetime-time0-0-evaluates-as-false-in-boolean-context>.

Indeed, why should the result of 4 - 4 have a different truth-value than 4 - 3 ? This implementation seems to be a legacy from languages without boolean types.
--
https://mail.python.org/mailman/listinfo/python-list

Reply via email to