Pythonic emptiness checking
r
rt8396 at gmail.com
Wed Apr 29 09:45:17 EDT 2009
On Apr 29, 8:37 am, Filip Gruszczyński <grusz... at gmail.com> wrote:
> 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?
It also works for numbers and tuples and... All types have a value in
python try the bool() function
> 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++.
Well you could do either or, but i very much like the simplicity of
if <value>:
do this
"Python is simplistic programming bliss. don't thank God, thank
Guido!"
More information about the Python-list
mailing list