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


Groups > comp.lang.python > #25343

Re: Implicit conversion to boolean in if and while statements

Path csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!xlned.com!feeder7.xlned.com!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <rosuav@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.030
X-Spam-Evidence '*H*': 0.94; '*S*': 0.00; 'say,': 0.05; 'none.': 0.09; 'subject:while': 0.09; 'value.': 0.15; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'wrote:': 0.17; 'received:209.85.214.174': 0.21; '15,': 0.23; 'seems': 0.23; 'header:In-Reply-To:1': 0.25; 'andrew': 0.27; 'converting': 0.27; 'message-id:@mail.gmail.com': 0.27; 'starts': 0.29; 'point': 0.31; 'values.': 0.33; 'to:addr:python-list': 0.33; 'languages': 0.33; 'received:google.com': 0.34; 'or,': 0.34; 'false': 0.35; 'pm,': 0.35; 'received:209.85': 0.35; 'but': 0.36; 'received:209': 0.37; 'subject:: ': 0.38; 'to:addr:python.org': 0.39; 'received:209.85.214': 0.39; 'header:Received:5': 0.40; 'skip:u 10': 0.60; 'jul': 0.65; 'treat': 0.65; 'fact,': 0.69
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=OoufxCeS9YPi4JdXEXW0CAhM2uEUxj0q6SfBuJYbVS8=; b=Fx2RUEd5bzdO+sqJokZZ397IjsZQh/ORoaILcwDrNSMOYFxGWV3y+roJN38jraFCci zGQfzTGP7ex5rmOYNwPcOLypItdvV5TrfdLWMMFq8p1LLETVPQ/lJjg0BdOnO6OnDxnc 2TPVbfZ94fLG5sdh7ywX0/pzAxKVhRbQtHH9sGquGLrvFNABvorvPTUjePd0w/wR6Rgv VsTnWxpT2ZYSsMWiJ5Pa83sK1CeEu28UhW3j3M9kGb/SMNKyASLEK8zVloiHabEHeiHm HHzic1DoDVCDKM1Wuch2YWRnDxkCBRbHyed9fhnSslMjk3I3JV82tZ5weCB/JAhUz8KQ hgCQ==
MIME-Version 1.0
In-Reply-To <500280A6.6070608@gmail.com>
References <500280A6.6070608@gmail.com>
Date Sun, 15 Jul 2012 18:47:05 +1000
Subject Re: Implicit conversion to boolean in if and while statements
From Chris Angelico <rosuav@gmail.com>
To python-list@python.org
Content-Type text/plain; charset=ISO-8859-1
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.12
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.2134.1342342028.4697.python-list@python.org> (permalink)
Lines 12
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1342342029 news.xs4all.nl 6938 [2001:888:2000:d::a6]:45593
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:25343

Show key headers only | View raw


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

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


Thread

Re: Implicit conversion to boolean in if and while statements Chris Angelico <rosuav@gmail.com> - 2012-07-15 18:47 +1000

csiph-web