Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #52349 > unrolled thread
| Started by | Chris Angelico <rosuav@gmail.com> |
|---|---|
| First post | 2013-08-11 04:20 +0100 |
| Last post | 2013-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.
Re: Python Basic Doubt Chris Angelico <rosuav@gmail.com> - 2013-08-11 04:20 +0100
| From | Chris Angelico <rosuav@gmail.com> |
|---|---|
| Date | 2013-08-11 04:20 +0100 |
| Subject | Re: 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
Back to top | Article view | comp.lang.python
csiph-web