diff Doc/lib/libstdtypes.tex @ 28606:436d812f2b94 legacy-trunk

- list.insert(i, x) now interprets negative i as it would be interpreted by slicing, so negative values count from the end of the list. This was the only place where such an interpretation was not placed on a list index.
author Guido van Rossum <guido@python.org>
date Mon, 14 Apr 2003 20:58:14 +0000
parents 90f17c374f59
children 06abfc9c68e7
line wrap: on
line diff
--- a/Doc/lib/libstdtypes.tex	Mon Apr 14 18:47:28 2003 +0000
+++ b/Doc/lib/libstdtypes.tex	Mon Apr 14 20:58:14 2003 +0000
@@ -941,8 +941,7 @@
   \lineiii{\var{s}.index(\var{x})}
     {return smallest \var{i} such that \code{\var{s}[\var{i}] == \var{x}}}{(4)}
   \lineiii{\var{s}.insert(\var{i}, \var{x})}
-	{same as \code{\var{s}[\var{i}:\var{i}] = [\var{x}]}
-	  if \code{\var{i} >= 0}}{(5)}
+	{same as \code{\var{s}[\var{i}:\var{i}] = [\var{x}]}}{(5)}
   \lineiii{\var{s}.pop(\optional{\var{i}})}
     {same as \code{\var{x} = \var{s}[\var{i}]; del \var{s}[\var{i}]; return \var{x}}}{(6)}
   \lineiii{\var{s}.remove(\var{x})}
@@ -982,8 +981,10 @@
   \var{s}.
 
 \item[(5)] When a negative index is passed as the first parameter to
-  the \method{insert()} method, the new element is prepended to the
-  sequence.
+  the \method{insert()} method, the list length is added, as for slice
+  indices.  If it is still negative, it is truncated to zero, as for
+  slice indices.  \versionchanged[Previously, all negative indices
+  were truncated to zero]{2.3}
 
 \item[(6)] The \method{pop()} method is only supported by the list and
   array types.  The optional argument \var{i} defaults to \code{-1},