[Python-Dev] List insert at index that is well out of range - behaves like append
Antoine Pitrou
solipsis at pitrou.net
Tue Sep 16 00:54:03 CEST 2014
On Mon, 15 Sep 2014 23:46:03 +0100
Mark Lawrence <breamoreboy at yahoo.co.uk> wrote:
>
> I assume it's based on the concepts of slicing. From the docs
> "s.insert(i, x) - inserts x into s at the index given by i (same as
> s[i:i] = [x])". Although shouldn't that read s[i:i+1] = [x] ?
No, the latter would replace the contents at index i, while the former
inserts it (formally, it replaces the 0-length slice with a 1-length
slice).
Regards
Antoine.
More information about the Python-Dev
mailing list