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


Groups > comp.lang.python > #52349

Re: Python Basic Doubt

Path csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!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.014
X-Spam-Evidence '*H*': 0.97; '*S*': 0.00; 'operator': 0.03; 'subject:Python': 0.06; 'false.': 0.09; 'bool': 0.16; 'boolean': 0.16; 'false:': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'wrote:': 0.18; 'normally': 0.19; '>>>': 0.22; 'aug': 0.22; 'print': 0.22; 'adds': 0.24; 'interpret': 0.24; 'header:In-Reply-To:1': 0.27; 'am,': 0.29; 'message- id:@mail.gmail.com': 0.30; 'code': 0.31; 'equality': 0.31; 'another': 0.32; 'received:google.com': 0.35; 'false': 0.36; 'i.e.': 0.36; 'possible': 0.36; 'level': 0.37; 'to:addr:python- list': 0.38; 'to:addr:python.org': 0.39; 'either': 0.39; 'simply': 0.61; 'here': 0.66; 'whereas': 0.91; '2013': 0.98
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=CSFyMGLe2+DpAAHLoNIRmEXhlWF+PxN7KE6GCb5XIcs=; b=YzztXGjSOxniZrxs7mAvt679qv14CYfz4P5GPMJwOqu7CN5LNtqdrpQwVlyXOV+doz E2WU5u+abkgitmJ0GP78poEO+FgqE0mAxyT+o/YnO8IAQRdnBeoJAHW7soK2QIq3KAw2 /acgohmjJhY6UHz+grNk/g5lXs4Y0tbsWUFZ+nWWl1q2aiL2+UML9GqYkBGedCHnk9SM IT7u2t4uBf7TGgrMtFjs5v+20gfFnS8CS61qbR/nfhwl9InrcH/PS8je4g3p/A1pnBgh do8/wdisH0a32IWRreC3+rbdSYeDOhg3OJKGX+Lap1kGpSgaWJbLOMPDuy6r9rAw9RD8 +DYA==
MIME-Version 1.0
X-Received by 10.52.34.40 with SMTP id w8mr3077343vdi.7.1376191203721; Sat, 10 Aug 2013 20:20:03 -0700 (PDT)
In-Reply-To <CAL0E0u69NXDrtojK4dUY+EcP5e9ab5BYkXb-M3Dz=+BTWpKmSA@mail.gmail.com>
References <CAL0E0u6wO_UBniWoSpePvhKhPDG_nf4p1rqYYrGwzoHTqp6ZHA@mail.gmail.com> <20130810114040.6ac78fe8@bigbox.christie.dr> <CAL0E0u69NXDrtojK4dUY+EcP5e9ab5BYkXb-M3Dz=+BTWpKmSA@mail.gmail.com>
Date Sun, 11 Aug 2013 04:20:03 +0100
Subject Re: Python Basic Doubt
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.15
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.456.1376191211.1251.python-list@python.org> (permalink)
Lines 43
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1376191211 news.xs4all.nl 15953 [2001:888:2000:d::a6]:42836
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:52349

Show key headers only | View raw


On Sun, Aug 11, 2013 at 4:09 AM, Krishnan Shankar
<i.am.songoku@gmail.com> wrote:
> i.e. Is this code possible
>
> if a is False:
>     print 'Yes'
> if b is False:
>     print 'No'

You would use that if you want to check if a/b is the exact bool value
False. Normally you would simply spell it thus:

if not a:
    print 'Yes'
if not b:
    print 'No'

which will accept any value and interpret it as either empty (false)
or non-empty (true).

Using the equality operator here adds another level of potential confusion:

>>> 0 == False
True
>>> [] == False
False
>>> 0.0 == False
True
>>> () == False
False

whereas if you use the normal boolean conversion, those ARE all false:

>>> bool(0)
False
>>> bool([])
False
>>> bool(0.0)
False
>>> bool(())
False

ChrisA

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


Thread

Re: Python Basic Doubt Chris Angelico <rosuav@gmail.com> - 2013-08-11 04:20 +0100

csiph-web