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


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

Re: Python Basic Doubt

Started byChris Angelico <rosuav@gmail.com>
First post2013-08-11 04:20 +0100
Last post2013-08-11 04:20 +0100
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: Python Basic Doubt Chris Angelico <rosuav@gmail.com> - 2013-08-11 04:20 +0100

#52349 — Re: Python Basic Doubt

FromChris Angelico <rosuav@gmail.com>
Date2013-08-11 04:20 +0100
SubjectRe: Python Basic Doubt
Message-ID<mailman.456.1376191211.1251.python-list@python.org>
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

[toc] | [standalone]


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


csiph-web