2
We know the objects of the type list
, because they are based on dynamic vectors, it has a maximum internal capacity. We also know that when this total capacity is reached and we want to insert a new value in the list, Python allocates a new array with a capacity greater than the previous one and transfers all values of the array previous to the new array. But how the language allocates a new portion of memory without losing the reference of the previous one?
lst = []
print(id(lst))
for i in range(999):
lst.append(i)
print(id(lst))
When executing the code, we can see that the id’s will be the same, even after the resizing operations. How is this possible?