Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
d8ede4fd
Commit
d8ede4fd
authored
Oct 12, 2013
by
Georg Brandl
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Closes #13203: add a FAQ section about seemingly duplicate id()s.
parent
4b532596
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
26 additions
and
0 deletions
+26
-0
Doc/faq/programming.rst
Doc/faq/programming.rst
+26
-0
No files found.
Doc/faq/programming.rst
View file @
d8ede4fd
...
...
@@ -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
=======
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment