Pythonic emptiness checking
pavlovevidence at gmail.com
Thu Apr 30 03:03:03 CEST 2009
On Apr 29, 6:46 am, Bruno Desthuilliers <bruno.
42.desthuilli... at websiteburo.invalid> wrote:
> Filip Gruszczyński a écrit :
> > One of the Python Zen rules is Explicit is better implicit. And yet
> > it's ok to do:
> > if x:
> > do_sth
> > when x is string or list. Since it's very comfy, I've got nothing
> > against though. I am just curious, why is it so?
> Because it is explicit (or at least considered as such) that in Python,
> an empty list or string (as well as empty tuples, dicts and sets and
> numeric zeros, False and None) have a false value in a boolean context.
I think a better answer to this question is: "The Zen of Python is not
called the Cold Hard Rules of Python"; in this case the language goes
against this particluar Zen as it does in many other places.
More information about the Python-list