Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #52310 > unrolled thread
| Started by | Tim Chase <python.list@tim.thechases.com> |
|---|---|
| First post | 2013-08-10 11:40 -0500 |
| Last post | 2013-08-10 11:40 -0500 |
| 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 Tim Chase <python.list@tim.thechases.com> - 2013-08-10 11:40 -0500
| From | Tim Chase <python.list@tim.thechases.com> |
|---|---|
| Date | 2013-08-10 11:40 -0500 |
| Subject | Re: Python Basic Doubt |
| Message-ID | <mailman.429.1376152765.1251.python-list@python.org> |
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 top | Article view | comp.lang.python
csiph-web