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

2014年9月15日 15:55:41 -0700

On 2014年9月15日 23:46:03 +0100
Mark Lawrence <[email protected]> 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.
_______________________________________________
Python-Dev mailing list
[email protected]
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to