Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.mixmin.net!news.albasani.net!newsfeed.freenet.ag!news2.euro.net!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.046 X-Spam-Evidence: '*H*': 0.91; '*S*': 0.00; '16,': 0.03; '"if': 0.09; 'subject:while': 0.09; 'def': 0.10; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'mon,': 0.16; 'wrote:': 0.17; '>>>': 0.18; 'received:209.85.214.174': 0.21; 'least': 0.25; 'header:In-Reply-To:1': 0.25; 'possibility': 0.27; 'used,': 0.27; 'question': 0.27; 'message-id:@mail.gmail.com': 0.27; 'to:addr :python-list': 0.33; 'received:google.com': 0.34; 'doing': 0.35; 'pm,': 0.35; 'received:209.85': 0.35; 'there': 0.35; 'why': 0.37; 'received:209': 0.37; 'subject:: ': 0.38; 'behind': 0.38; 'to:addr:python.org': 0.39; 'received:209.85.214': 0.39; 'header:Received:5': 0.40; 'valuable': 0.60; 'information': 0.63; 'jul': 0.65; 'obvious': 0.71; 'proves': 0.84; 'essence': 0.91; 'rick': 0.91 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=3xykanyxp4YdL1J8LY+1xrOZnwlSLrQZ27NpeKYNWSI=; b=EY1N5ySlhMPWPicvmIMNREyb9ZokumT053oxkUuXv2pI4a1Gpqo3ZrIRKSgg7INB8A 9nVGoRuG9qiLbs53icBrRXB/PxfrUVt1VBPMs2mIidMXrvEO1ASYYUMe95wqaWyqXahF hnWRjG6Co9fCFjaxwg/1WfucsVV5QMDzGaNjP/lkm88DN0WVrYuEMNMgOcz89qX8CwNJ pXUuO8eTXI0WukKnXybiKpDNgTmqgExF0ihMk3xl299iak1OLXulnIcViHiqXmIL6QI3 w2mOW0aJWUmQ33wKSuZyXldv9j+dQyBft2wEi8LcGDKugQRFzNP1lX+LDicoYM+4ht/X ENNg== MIME-Version: 1.0 In-Reply-To: References: <5002a1f9$0$29995$c3e8da3$5496439d@news.astraweb.com> <7b027612-a07e-40f9-8ad2-3e95c5440482@googlegroups.com> <86872ad2-fda0-403b-9f18-d1cb18e41860@t32g2000yqd.googlegroups.com> <50039290$0$29978$c3e8da3$5496439d@news.astraweb.com> Date: Mon, 16 Jul 2012 15:57:39 +1000 Subject: Re: Implicit conversion to boolean in if and while statements From: Chris Angelico 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 19 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1342418263 news.xs4all.nl 6973 [2001:888:2000:d::a6]:46556 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:25395 On Mon, Jul 16, 2012 at 2:53 PM, Ranting Rick wrote: > "if obj" is in essence doing "if bool(obj)" behind the scenes. My > question is: Why hide such valuable information from the reader? It's > obvious that "if bool(obj)" will return a boolean; whereas "if obj" is > ambiguous. Proves nothing. At least when there are less names used, there's less possibility of monkey-patching. >>> def bool(n): ... return 5 ... >>> if bool([]): ... print("Yay?") ... Yay? ChrisA