As you can see from the source code, the data stored in the Pylistobject is Pyobject **ob_item, which is a similar method as a vector.
Items must normally not is NULL, which means that the elements in the list are removed from the list and are not immediately free, but placed in the cache pool of the list. This is different from an integer, a string object. The list's cache pool is empty when initialized, and in the use of the list, the deleted elements are constantly placed in the cache pool.
Because list is inherently used to insert or delete frequently. So how do you manage memory? Here, allocated is used to manage the size of each request memory. Similar to the concept of caching, when the existing memory size is not enough to use, the list directly new request another large memory. And the size of this new memory is allocated.
The initialization of the list is done in pylist_new.
Once the Pylistobject object is created, it is possible to add and revise its item. This is similar to C + + vectors. Or you can read it directly.
SOURCE Modification:
Observe the difference between allocated and ob_size according to the book first.
Can clearly see the change of allocated. Almost like C + + Vetor.
Python List Object