Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #52311 > unrolled thread
| Started by | Chris Angelico <rosuav@gmail.com> |
|---|---|
| First post | 2013-08-10 17:42 +0100 |
| Last post | 2013-08-10 17:42 +0100 |
| 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 Chris Angelico <rosuav@gmail.com> - 2013-08-10 17:42 +0100
| From | Chris Angelico <rosuav@gmail.com> |
|---|---|
| Date | 2013-08-10 17:42 +0100 |
| Subject | Re: Python Basic Doubt |
| Message-ID | <mailman.430.1376152947.1251.python-list@python.org> |
On Sat, Aug 10, 2013 at 4:33 PM, Krishnan Shankar <i.am.songoku@gmail.com> wrote: > Hi Fellow Python Friends, > > I am new to Python and recently subscribed to the mailing list.I have a > doubt regarding the basics of Python. Please help me in understanding the > below concept. > > So doubt is on variables and their contained value. Tangential to this: Python doesn't have "variables" that "contain" anything, but rather has names that are bound to (point to, if you like) objects. You're mostly right, this is just a terminology point. > Why does in the below example from Interpreter exploration value of c take > pre existing memory location. > >>>> 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? CPython caches a number of integer objects for efficiency. Whenever you ask for the integer 10, you'll get the _same_ integer 10. But if you try the same exercise with a much higher number, or with a different value, you should get a unique id. With immutable literals, the interpreter's allowed to reuse them. You don't normally care about the id() of an integer, and nor should you. Same goes for strings; the interpreter's allowed to intern them if it chooses. Generally, don't assume that they're different, don't assume they're the same either. ChrisA
Back to top | Article view | comp.lang.python
csiph-web