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


Groups > comp.lang.python > #16205 > unrolled thread

Re: Strange result ffor object to bool

Started byChris Angelico <rosuav@gmail.com>
First post2011-11-25 19:46 +1100
Last post2011-11-25 19:46 +1100
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

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

#16205 — Re: Strange result ffor object to bool

FromChris Angelico <rosuav@gmail.com>
Date2011-11-25 19:46 +1100
SubjectRe: Strange result ffor object to bool
Message-ID<mailman.3029.1322210780.27778.python-list@python.org>
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

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web