Check if variable is defined

Todd A. Jacobs tjacobs at
Thu May 17 05:27:00 EDT 2001

On Thu, 17 May 2001, Tim Peters wrote:

>     if beatsme is None:
>         print "beatsme wasn't assigned anything meaningful yet"

This works. It also turns out that:

	if foo: print "true"	# print true if foo not empty

works too, which is the behavior I was looking for. It doesn't work quite
so well on numbers (your example works better), but is fine for lists,
which is what I really needed anyway: something to detect empty lists.

Todd A. Jacobs
CodeGnome Consulting, LTD

More information about the Python-list mailing list