Pythonic emptiness checking

Filip Gruszczyński gruszczy at
Wed Apr 29 15:37:13 CEST 2009

One of the Python Zen rules is Explicit is better implicit. And yet
it's ok to do:

if x:

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?

And one more thing: is it ok to do

if x:

instead of

if x is not None:

Because I often encounter it and would like to know, if I can simplify
it. Especially that I liked similar construction in C/C++.

Filip Gruszczyński

More information about the Python-list mailing list