Operator Precedence/Boolean Logic
lawrencedo99 at gmail.com
Thu Jun 23 00:47:05 EDT 2016
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
>> “...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>.
More information about the Python-list