@@ -1172,16 +1172,28 @@ You probably tried to make a multidimensional array like this::
11721172
11731173 >>> A = [[None] * 2] * 3
11741174
1175- This looks correct if you print it::
1175+ This looks correct if you print it:
1176+
1177+ .. testsetup ::
1178+
1179+ A = [[None] * 2] * 3
1180+
1181+ .. doctest ::
11761182
11771183 >>> A
11781184 [[None, None], [None, None], [None, None]]
11791185
11801186But when you assign a value, it shows up in multiple places:
11811187
1182- >>> A[0 ][0 ] = 5
1183- >>> A
1184- [[5, None], [5, None], [5, None]]
1188+ .. testsetup ::
1189+
1190+ A = [[None] * 2] * 3
1191+
1192+ .. doctest ::
1193+
1194+ >>> A[0 ][0 ] = 5
1195+ >>> A
1196+ [[5, None], [5, None], [5, None]]
11851197
11861198The reason is that replicating a list with ``* `` doesn't create copies, it only
11871199creates 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
16651677next freshly created object is allocated at the same position in memory. This
16661678is illustrated by this example:
16671679
1668- >>> id (1000 )
1680+ >>> id (1000 ) # doctest: +SKIP
1669168113901272
1670- >>> id (2000 )
1682+ >>> id (2000 ) # doctest: +SKIP
1671168313901272
16721684
16731685The 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
16761688to the object:
16771689
16781690>>> a = 1000 ; b = 2000
1679- >>> id (a)
1691+ >>> id (a) # doctest: +SKIP
1680169213901272
1681- >>> id (b)
1693+ >>> id (b) # doctest: +SKIP
1682169413891296
16831695
16841696
0 commit comments