Strange result ffor object to bool
Chris Angelico
rosuav at gmail.com
Fri Nov 25 03:46:17 EST 2011
On Fri, Nov 25, 2011 at 5:52 PM, ZhouPeng <zpengxen at gmail.com> wrote:
> I am sure listen is not None and can be accessed properly.
>
> But print bool(listen) is False
> if not listen is True
Casting something to boolean follows strict rules derived from the
notion that emptiness is false and nonemptiness is true. For instance:
>>> bool(""),bool([]),bool({}),bool(0)
(False, False, False, False)
Details here: http://docs.python.org/library/stdtypes.html
Chris Angelico
More information about the Python-list
mailing list