1nums = [7, 3, 9, 5]2nums[0]3nums[2]4nums[-1]5len(nums)6nums[1:3]7nums.append(2)8nums.insert(0, 8)9for n in nums: print(n)nums10001008101610241032104010481056739528
Code card: the program; the highlighted line is the one runningSlots: side by side in memory, address on the front, index plate in frontItem cubes: the values the slots refer tonums header: the list's length and how many slots it has room forA Python list keeps its items in slots that sit side by side in memory, numbered from 0. Reading nums[i] works out the slot's address directly (start + i × 8), so it takes the same time for any index. Each slot holds a reference to its item. append uses spare room the list keeps for growing; insert(0, x) has to move every item one slot to the right first. The addresses 1000, 1008, ... are made up to keep the sums easy; real addresses are much larger numbers. The rule start + index × size is how any array finds a slot.

Slots and indexes

  1. Line 1 makes a list of four items. Python stores them in slots that sit side by side in memory, in the order you wrote them, and keeps a note of how many there are.

Reading is instant

Counting and slicing

Changing the list

Try it in the Python prompt

;; step 1/10 · line 1: nums = [7, 3, 9, 5]
>>> nums = [7, 3, 9, 5]
>>> nums
[7, 3, 9, 5]
>>> type(nums)
<class 'list'>

The addresses 1000, 1008, ... are made up to keep the sums easy; real addresses are much larger numbers. The rule start + index × size is how any array finds a slot. In CPython each slot holds a reference (a C pointer), 8 bytes on a 64-bit computer. The items themselves are objects stored elsewhere in memory. The exact growth is an implementation detail. In CPython 3.14 the list [7, 3, 9, 5] has room for exactly 4, and the first append grows it to room for 8 (sys.getsizeof shows 88, then 120 bytes). Growing may copy the references to a new, bigger block.