What values are considered false?

Jeff Shannon jeff at ccvcorp.com
Thu Feb 21 14:45:20 EST 2002


Jeff Henry wrote:

> Roy Smith wrote:
> >
> > Roy Smith <roy at panix.com> wrote:
> > > PS -- In the lists of false things in python that have been mentioned on
> > > this thread, I don't think I've seen anybody mention {}, the empty
> > > dictionary.
> >
> > Along those same lines, I half-expected the empty function to be false,
> > i.e.:
> >
> > def foo():
> >    pass
> >
> > if (foo):
>
> Oops! I think you meant to say -
>
> if (foo()):

No, he meant the first way.  The intent is to test whether an "empty" code block
is considered false or not.  It's not -- even "empty", there's something there,
so it's considered true.

(This may not be so surprising, when you consider that this function is *not*
equivalent to a NOP -- it creates a frame object, passes control to it, returns
None, and destroys the frame object.)

Jeff Shannon
Technician/Programmer
Credit International





More information about the Python-list mailing list