Path: csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!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.015 X-Spam-Evidence: '*H*': 0.97; '*S*': 0.00; 'subject:Python': 0.06; 'correct.': 0.07; 'none:': 0.07; 'none):': 0.09; 'parameter': 0.09; 'def': 0.12; 'false:': 0.16; 'from:addr:torriem': 0.16; 'from:name:michael torrie': 0.16; 'mylist': 0.16; 'operator.': 0.16; 'pythonic': 0.16; 'wrote:': 0.18; 'do.': 0.18; 'print': 0.22; 'header:User-Agent:1': 0.23; 'header:In-Reply-To:1': 0.27; 'correct': 0.29; 'chris': 0.29; 'code': 0.31; 'lists': 0.32; 'probably': 0.32; 'done.': 0.35; 'but': 0.35; 'there': 0.35; 'i.e.': 0.36; 'possible': 0.36; 'should': 0.36; 'wrong': 0.37; 'list': 0.37; 'message-id:@gmail.com': 0.38; 'to:addr:python- list': 0.38; 'pm,': 0.38; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'times': 0.62; 'more': 0.64; 'believe': 0.68; 'default': 0.69; 'idiom': 0.84; 'avoided.': 0.91; 'colleagues': 0.97 X-Virus-Scanned: amavisd-new at torriefamily.org Date: Sat, 10 Aug 2013 21:35:31 -0600 From: Michael Torrie User-Agent: Mozilla/5.0 (X11; Linux i686; rv:10.0.12) Gecko/20130105 Thunderbird/10.0.12 MIME-Version: 1.0 To: python-list@python.org Subject: Re: Python Basic Doubt References: <20130810114040.6ac78fe8@bigbox.christie.dr> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 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: 24 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1376192149 news.xs4all.nl 15863 [2001:888:2000:d::a6]:51095 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:52352 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 = []