Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #52324
| From | Dennis Lee Bieber <wlfraed@ix.netcom.com> |
|---|---|
| Subject | Re: Python Basic Doubt |
| Date | 2013-08-10 16:30 -0400 |
| Organization | IISS Elusive Unicorn |
| References | <CAL0E0u6wO_UBniWoSpePvhKhPDG_nf4p1rqYYrGwzoHTqp6ZHA@mail.gmail.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.439.1376166663.1251.python-list@python.org> (permalink) |
On Sat, 10 Aug 2013 21:03:36 +0530, Krishnan Shankar
<i.am.songoku@gmail.com> declaimed the following:
>
>>>> 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?
>
Because id(n) is not giving you the address of the NAME. It is giving
you the address of the "10" -- and small integers are cached and reused in
most Python implementations.
Compare:
>>> a = 12345
>>> id(a)
56674472L
>>> b = a
>>> id(b)
56674472L
>>> c = 12345
>>> id(c)
56674688L
>>> a = 11
>>> id(a)
4472248L
>>> b = a
>>> id(b)
4472248L
>>> c = 11
>>> id(c)
4472248L
>>>
--
Wulfraed Dennis Lee Bieber AF6VN
wlfraed@ix.netcom.com HTTP://wlfraed.home.netcom.com/
Back to comp.lang.python | Previous | Next — Next in thread | Find similar | Unroll thread
Re: Python Basic Doubt Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2013-08-10 16:30 -0400
Re: Python Basic Doubt Roy Smith <roy@panix.com> - 2013-08-10 16:42 -0400
Re: Python Basic Doubt Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-08-11 08:29 +0000
csiph-web