When inserting to a negative index (negative indexes for list is impossible, i think?), or inserting far beyond the current index, list.insert
does not produce IndexError
, instead it just silently ignores the index and pretend you called list.append()
instead, why? I expected both of these to generate IndexError
s
l = list()
l.insert(999, 999) # expected index error because the highest valid index is 0, not 999?
l.insert(-999, -999) # expected index error because negative indexes are impossible?
print(l) # prints [-999, 999]
but instead of they just act as if i had written
l = list()
l.append(999)
l.append(-999)
why?