[Python-checkins] cpython (merge 3.3 -> default): merge with 3.3

georg.brandl python-checkins at python.org
Sat Oct 12 18:14:34 CEST 2013


http://hg.python.org/cpython/rev/5e756a93d83b
changeset:   86231:5e756a93d83b
parent:      86228:cff4dd674efe
parent:      86230:0d5de993db66
user:        Georg Brandl <georg at python.org>
date:        Sat Oct 12 18:15:21 2013 +0200
summary:
  merge with 3.3

files:
  Doc/faq/programming.rst |  26 ++++++++++++++++++++++++++
  1 files changed, 26 insertions(+), 0 deletions(-)


diff --git a/Doc/faq/programming.rst b/Doc/faq/programming.rst
--- a/Doc/faq/programming.rst
+++ b/Doc/faq/programming.rst
@@ -1599,6 +1599,32 @@
 keeping a list of weak references to each instance.
 
 
+Why does the result of ``id()`` appear to be not unique?
+--------------------------------------------------------
+
+The :func:`id` builtin returns an integer that is guaranteed to be unique during
+the lifetime of the object.  Since in CPython, this is the object's memory
+address, it happens frequently that after an object is deleted from memory, the
+next freshly created object is allocated at the same position in memory.  This
+is illustrated by this example:
+
+>>> id(1000)
+13901272
+>>> id(2000)
+13901272
+
+The two ids belong to different integer objects that are created before, and
+deleted immediately after execution of the ``id()`` call.  To be sure that
+objects whose id you want to examine are still alive, create another reference
+to the object:
+
+>>> a = 1000; b = 2000
+>>> id(a)
+13901272
+>>> id(b)
+13891296
+
+
 Modules
 =======
 

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list