Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!xlned.com!feeder7.xlned.com!newsfeed.xs4all.nl!newsfeed3a.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.009 X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; 'subject:Python': 0.06; 'assignment': 0.07; 'assigning': 0.09; 'subject:into': 0.09; 'cc:addr:python-list': 0.11; 'confuse': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'identities': 0.16; 'immutable,': 0.16; 'subject:variable': 0.16; 'wrote:': 0.18; 'feb': 0.22; 'cc:addr:python.org': 0.22; 'integer': 0.24; 'cc:2**0': 0.24; 'header:In-Reply-To:1': 0.27; 'specifically': 0.29; 'message-id:@mail.gmail.com': 0.30; 'such.': 0.31; 'values.': 0.31; 'another': 0.32; 'fri,': 0.33; 'but': 0.35; 'received:google.com': 0.35; 'false': 0.36; 'subject:?': 0.36; 'should': 0.36; 'being': 0.38; 'pm,': 0.38; 'subject:Can': 0.60; 'simple': 0.61; "you're": 0.61; 'safe.': 0.84; 'to:none': 0.92 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc :content-type; bh=Z6wbZt7DPyeaiR7xlIspizujlwcWOB3MB6fQN/Sebe8=; b=0ZdKxJe+wHdcQTsBm8m6450McEcuLirDE9M1jnJV7w4GoK9N0BgulR9ujAlEk+7wS+ JI13gEPr0oArDWsysEK7IMv7qPM+xaULqb/FD/r7reCxB0xXUdGH+ozlZN9VD/UHpqBA 17Ir9QQ6ZtoNNwCqvCy6JTbqV6GfhW7sqs2mYnqQy8FQkHYdIPdCMxxX5/bPvmBuiCca EmIh0l095lvCT0BmXBmGzA6xp7TkP01YSp1DLSTB6+wcudCL1lclCJ8wZSJPy+bxGKKU ieayLqzF16dOAKFwBIPtj/JHs5aHEBM+pPjpAbnNdaW0ZJ9IuKcOuagtocyZgG+EGdp0 ba4g== MIME-Version: 1.0 X-Received: by 10.68.201.10 with SMTP id jw10mr1036267pbc.25.1393562603243; Thu, 27 Feb 2014 20:43:23 -0800 (PST) In-Reply-To: References: <27ac2248-0ca3-4ba6-9d25-eaad324bc5e9@googlegroups.com> <5f4f5a5f-327a-4616-8235-17ee9e74c488@googlegroups.com> <530fef58$0$11113$c3e8da3@news.astraweb.com> Date: Fri, 28 Feb 2014 15:43:23 +1100 Subject: Re: Can global variable be passed into Python function? From: Chris Angelico Cc: "python-list@python.org" Content-Type: text/plain; charset=UTF-8 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: 1393562612 news.xs4all.nl 2850 [2001:888:2000:d::a6]:53996 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:67194 On Fri, Feb 28, 2014 at 1:29 PM, Mark H. Harris wrote: > a=1024 > b=a > b=1024 > a is b > False No no no no! They're not pointing to the same integer any more. Now, if you change the "b=1024" from being a mostly-useless assignment (to another int with the same value) into being a comparison, then it'll be safe. But you're assigning "b=a" and then immediately reassigning "b=1024". Simple rule of thumb: Never use 'is' with strings or ints. They're immutable, their identities should be their values. Playing with 'is' will only confuse you, unless you're specifically going for introspection and such. ChrisA