summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGeorg Brandl <georg@python.org>2013-10-12 16:15:21 (GMT)
committerGeorg Brandl <georg@python.org>2013-10-12 16:15:21 (GMT)
commit42840f017d7345c83e907208a3d7d476557ea4ed (patch)
treed6ff66f2cd9d8706d99b9a43e58c104fe277a563
parent4ae423ded4741b303b7006dcdcd360bec5549fff (diff)
parentd8ede4fddd5305ced045d07e95c70cdea1d097af (diff)
downloadcpython-42840f017d7345c83e907208a3d7d476557ea4ed.zip
cpython-42840f017d7345c83e907208a3d7d476557ea4ed.tar.gz
cpython-42840f017d7345c83e907208a3d7d476557ea4ed.tar.bz2
merge with 3.3
-rw-r--r--Doc/faq/programming.rst26
1 files changed, 26 insertions, 0 deletions
diff --git a/Doc/faq/programming.rst b/Doc/faq/programming.rst
index bf73935..12f1a2d 100644
--- a/Doc/faq/programming.rst
+++ b/Doc/faq/programming.rst
@@ -1599,6 +1599,32 @@ You can program the class's constructor to keep track of all instances by
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
=======