diff options
author | Senthil Kumaran <senthil@uthcode.com> | 2016-06-05 03:08:10 (GMT) |
---|---|---|
committer | Senthil Kumaran <senthil@uthcode.com> | 2016-06-05 03:08:10 (GMT) |
commit | 2950776d36576ea3c8db937ae0a5df57a73f7c51 (patch) | |
tree | 071b511b776d30a021a69529f65838f8c2e3dc27 /Doc/faq | |
parent | 7a9ddd1d85453485240dd666d679f7b6729470e0 (diff) | |
parent | 7749320142326acae62b865c16fa450e5fb5ceb7 (diff) | |
download | cpython-2950776d36576ea3c8db937ae0a5df57a73f7c51.zip cpython-2950776d36576ea3c8db937ae0a5df57a73f7c51.tar.gz cpython-2950776d36576ea3c8db937ae0a5df57a73f7c51.tar.bz2 |
[merge from 3.5] - Issue27203 - Fix doctests Doc/faq/programming.rst.
Patch contributed by Jelle Zijlstra.
Diffstat (limited to 'Doc/faq')
-rw-r--r-- | Doc/faq/programming.rst | 28 |
1 files changed, 20 insertions, 8 deletions
diff --git a/Doc/faq/programming.rst b/Doc/faq/programming.rst index ac10ea5..9c5e20d 100644 --- a/Doc/faq/programming.rst +++ b/Doc/faq/programming.rst @@ -1172,16 +1172,28 @@ You probably tried to make a multidimensional array like this:: >>> A = [[None] * 2] * 3 -This looks correct if you print it:: +This looks correct if you print it: + +.. testsetup:: + + A = [[None] * 2] * 3 + +.. doctest:: >>> A [[None, None], [None, None], [None, None]] But when you assign a value, it shows up in multiple places: - >>> A[0][0] = 5 - >>> A - [[5, None], [5, None], [5, None]] +.. testsetup:: + + A = [[None] * 2] * 3 + +.. doctest:: + + >>> A[0][0] = 5 + >>> A + [[5, None], [5, None], [5, None]] The reason is that replicating a list with ``*`` doesn't create copies, it only creates references to the existing objects. The ``*3`` creates a list @@ -1665,9 +1677,9 @@ 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) +>>> id(1000) # doctest: +SKIP 13901272 ->>> id(2000) +>>> id(2000) # doctest: +SKIP 13901272 The two ids belong to different integer objects that are created before, and @@ -1676,9 +1688,9 @@ objects whose id you want to examine are still alive, create another reference to the object: >>> a = 1000; b = 2000 ->>> id(a) +>>> id(a) # doctest: +SKIP 13901272 ->>> id(b) +>>> id(b) # doctest: +SKIP 13891296 |