Operator Precedence/Boolean Logic

Antoon Pardon antoon.pardon at rece.vub.ac.be
Thu Jun 23 05:01:18 EDT 2016


Op 23-06-16 om 10:16 schreef Marko Rauhamaa:
> 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:
>         ...
>
> or:
>
>     if len(leftover) > 0:    # no, I'd never write this
>         ...

Well if I have to test for emptyness, I always write

   if len(seq) > 0:

Because this will throw an exception when len can't
apply to seq and so this will catch possible bugs
sooner than writing:

  if not seq.

-- 
Antoon Pardon





More information about the Python-list mailing list