Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed3.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.005 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'subject:not': 0.03; "subject:' ": 0.07; 'from:addr:ethan': 0.09; 'from:addr:stoneleaf.us': 0.09; 'from:name:ethan furman': 0.09; 'means,': 0.09; 'message-id:@stoneleaf.us': 0.09; 'objects,': 0.09; '~ethan~': 0.09; '"in': 0.16; '"is': 0.16; 'none.': 0.16; 'wrote:': 0.18; 'tests': 0.22; 'header:User-Agent:1': 0.23; 'comparing': 0.24; 'looks': 0.24; 'header:In-Reply-To:1': 0.27; 'correct': 0.29; '(which': 0.31; 'object.': 0.31; 'objects': 0.35; 'test': 0.35; 'but': 0.35; 'object,': 0.36; 'charset:us-ascii': 0.36; 'thanks': 0.36; 'wrong': 0.37; 'two': 0.37; 'easily': 0.37; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'to:addr:python.org': 0.39; 'anytime': 0.60; 'most': 0.60; 'received:173': 0.61; 'simply': 0.61; 'such': 0.63; 'talking': 0.65; 'answer.': 0.68 Date: Mon, 18 Aug 2014 14:42:24 -0700 From: Ethan Furman User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:16.0) Gecko/20121010 Thunderbird/16.0.1 MIME-Version: 1.0 To: python-list@python.org Subject: Re: 'is not' or '!=' References: <87fvgt7c4i.fsf@elektro.pacujo.net> In-Reply-To: Content-Type: text/plain; charset=us-ascii; format=flowed 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: 19 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1408398146 news.xs4all.nl 2881 [2001:888:2000:d::a6]:56595 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:76517 On 08/18/2014 01:58 PM, ElChino wrote: > "Marko Rauhamaa" wrote: > >> In almost all cases, both tests would result in the same behavior. >> However, the "is not" test is conceptually the correct one since you >> want to know if x is the one and only None object. You don't want to be >> fooled by an imposter object that simply looks like the None object. > > Thanks for this excellent answer. "Terve, terve". I don't know what "terve, terve" means, but the "in almost all cases" is only true when talking about singletons such as None. If you are not dealing with singletons (which is most cases), such as numbers, strings, lists, and most other arbitrary objects, you will need to use "!=" or anytime the two objects you are comparing are not the exact same object, you can easily get the wrong answer. -- ~Ethan~