Operator Precedence/Boolean Logic

Marko Rauhamaa marko at pacujo.net
Thu Jun 23 04:16:50 EDT 2016

Antoon Pardon <antoon.pardon at rece.vub.ac.be>:

> It is why I have sometime found the need to write:
>     if flag is True:
> Because flag needed to be True, not truthy.

Then, you have found the correct idiom for your rare need. You might
even want to consider:

   if flag is UP:
   elif flag is DOWN:
       assert flag is HALFMAST

I don't particularly like Python's falsey/truthy semantics, but I can
live with it. The biggest problem I have with it is the absence of an
emptiness predicate. I'd like to be able to write:

    if not leftover.empty():

or even:

    if not empty(leftover):

rather than having to say:

    if not leftover:


    if len(leftover) > 0:    # no, I'd never write this


More information about the Python-list mailing list