Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #16205

Re: Strange result ffor object to bool

References <CAAh7U5O-9u8b2=t3X8yfLdH_axEBoz1fQbr5=LTT2EYjoJVMvA@mail.gmail.com>
Date 2011-11-25 19:46 +1100
Subject Re: Strange result ffor object to bool
From Chris Angelico <rosuav@gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.3029.1322210780.27778.python-list@python.org> (permalink)

Show all headers | View raw


On Fri, Nov 25, 2011 at 5:52 PM, ZhouPeng <zpengxen@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

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: Strange result ffor object to bool Chris Angelico <rosuav@gmail.com> - 2011-11-25 19:46 +1100

csiph-web