Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #52310

Re: Python Basic Doubt

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <python.list@tim.thechases.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.002
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'operator': 0.03; 'cpython': 0.05; 'subject:Python': 0.06; 'cache': 0.07; 'none,': 0.07; 'variables': 0.07; 'assigning': 0.09; 'cc:addr:python-list': 0.11; 'python': 0.11; '"is"': 0.16; '-tkc': 0.16; 'caches': 0.16; 'from:addr:python.list': 0.16; 'from:addr:tim.thechases.com': 0.16; 'from:name:tim chase': 0.16; 'ironpython': 0.16; 'numbers).': 0.16; 'wrote:': 0.18; '>>>': 0.22; 'cc:addr:python.org': 0.22; 'integer': 0.24; "shouldn't": 0.24; 'versions': 0.24; 'cc:2**0': 0.24; 'cc:no real name:2**0': 0.24; 'compare': 0.26; 'values': 0.27; 'header:In-Reply-To:1': 0.27; 'exceptions': 0.31; 'ok.': 0.31; 'but': 0.35; 'there': 0.35; 'false': 0.36; 'doing': 0.36; 'charset:us-ascii': 0.36; 'anything': 0.39; 'future': 0.60; 'new': 0.61; 'range': 0.61; "you're": 0.61; 'different': 0.65; 'taking': 0.65; 'to:addr:gmail.com': 0.65; 'behavior': 0.77; '257': 0.84; 'location?': 0.84; 'received:50.22': 0.84
Date Sat, 10 Aug 2013 11:40:40 -0500
From Tim Chase <python.list@tim.thechases.com>
To Krishnan Shankar <i.am.songoku@gmail.com>
Subject Re: Python Basic Doubt
In-Reply-To <CAL0E0u6wO_UBniWoSpePvhKhPDG_nf4p1rqYYrGwzoHTqp6ZHA@mail.gmail.com>
References <CAL0E0u6wO_UBniWoSpePvhKhPDG_nf4p1rqYYrGwzoHTqp6ZHA@mail.gmail.com>
X-Mailer Claws Mail 3.8.1 (GTK+ 2.24.10; x86_64-pc-linux-gnu)
Mime-Version 1.0
Content-Type text/plain; charset=US-ASCII
Content-Transfer-Encoding 7bit
X-AntiAbuse This header was added to track abuse, please include it with any abuse report
X-AntiAbuse Primary Hostname - boston.accountservergroup.com
X-AntiAbuse Original Domain - python.org
X-AntiAbuse Originator/Caller UID/GID - [47 12] / [47 12]
X-AntiAbuse Sender Address Domain - tim.thechases.com
X-Get-Message-Sender-Via boston.accountservergroup.com: none
Cc python-list@python.org
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.429.1376152765.1251.python-list@python.org> (permalink)
Lines 38
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1376152765 news.xs4all.nl 15964 [2001:888:2000:d::a6]:34959
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:52310

Show key headers only | View raw


On 2013-08-10 21:03, Krishnan Shankar wrote:
> >>> a=10
> >>> id(a)
> 21665504
> >>> b=a
> >>> id(b)
> 21665504
> >>> c=10
> >>> id(c)
> 21665504
> 
> I am actually assigning new value to c. But from the value of id()
> all three variables take same location. With variables a and b it
> is ok. But why c taking the same location?

As an internal optimization, CPython caches small integer values 

  >>> a = 256
  >>> b = 256
  >>> a is b
  True
  >>> a = 257
  >>> b = 257
  >>> a is b
  False

Because it's an internal implementation detail, you shouldn't count
on this behavior (Jython or Cython or IronPython may differ; or
future versions of Python may cache a different range of numbers).

Generally, if you are using the "is" operator to compare against
anything other than None, you're doing it wrong. There are exceptions
to this, but it takes knowing the particulars.

-tkc


Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: Python Basic Doubt Tim Chase <python.list@tim.thechases.com> - 2013-08-10 11:40 -0500

csiph-web