Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #52352 > unrolled thread
| Started by | Michael Torrie <torriem@gmail.com> |
|---|---|
| First post | 2013-08-10 21:35 -0600 |
| Last post | 2013-08-10 21:35 -0600 |
| 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 Michael Torrie <torriem@gmail.com> - 2013-08-10 21:35 -0600
| From | Michael Torrie <torriem@gmail.com> |
|---|---|
| Date | 2013-08-10 21:35 -0600 |
| Subject | Re: Python Basic Doubt |
| Message-ID | <mailman.459.1376192149.1251.python-list@python.org> |
On 08/10/2013 09:09 PM, Krishnan Shankar wrote:
> i.e. Is this code possible
>
> if a is False:
> print 'Yes'
> if b is False:
> print 'No'
>
> Because i recommended this should not be done. But my colleagues say it is
> correct.
You are probably correct in your believe that this idiom should be
avoided. As Chris says, it's much more pythonic to just use if not a.
There is one case where the recommended idiom is to use the 'is'
operator. That's when you want an empty list as a default parameter to a
function. Since lists are mutable, often times using [] as a default
parameter is the wrong thing to do. This is the recommended idiom:
def my_func(mylist = None):
if mylist is None:
mylist = []
Back to top | Article view | comp.lang.python
csiph-web