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


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

Re: Implicit conversion to boolean in if and while statements

Started byChris Angelico <rosuav@gmail.com>
First post2012-07-15 18:47 +1000
Last post2012-07-15 18:47 +1000
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: Implicit conversion to boolean in if and while statements Chris Angelico <rosuav@gmail.com> - 2012-07-15 18:47 +1000

#25343 — Re: Implicit conversion to boolean in if and while statements

FromChris Angelico <rosuav@gmail.com>
Date2012-07-15 18:47 +1000
SubjectRe: Implicit conversion to boolean in if and while statements
Message-ID<mailman.2134.1342342028.4697.python-list@python.org>
On Sun, Jul 15, 2012 at 6:34 PM, Andrew Berg <bahamutzero8825@gmail.com> wrote:
> Converting 0 and 1 to False and True seems reasonable, but I don't see
> the point in converting other arbitrary values.

It's for convenience. Unfortunately, not all languages treat all types
the same way. It's very handy, though, to be able to use

if not foo: foo = some_initializer

when foo starts out as, say, None. Or []. Or, in fact, any other "empty" value.

ChrisA

[toc] | [standalone]


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


csiph-web