I had a list
a = [1, 2, 3]
when I did
a.insert(100, 100)
[1, 2, 3, 100]
as list was originally of siz
Perhaps the actual implementation will shed some light.
static int
ins1(PyListObject *self, Py_ssize_t where, PyObject *v)
{
...
if (where > n)
where = n;
...
}
So that answers the question of how.
Philosophically, lists are not arrays, and there are many list manipulations that are tolerant of weird indexing. For instance, l[1:1000] will return [2,3]. This is all meant as a convenience to the programmer.