[Python-Dev] List insert at index that is well out of range - behaves like append

Guido van Rossum guido at python.org
Tue Sep 16 00:57:17 CEST 2014

On Mon, Sep 15, 2014 at 3:46 PM, Mark Lawrence <breamoreboy at yahoo.co.uk>

> 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])".

Ah, right. It matches thigs like s[100:] which is the empty string if s is
shorter than 100.

> Although shouldn't that read s[i:i+1] = [x] ?

Should've stopped while you were ahead. :-)

'Nuff said.

--Guido van Rossum (python.org/~guido)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-dev/attachments/20140915/7bd50db3/attachment.html>

More information about the Python-Dev mailing list