Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ef428a2

Browse files
committed
Explain what [].insert() does when the target index is negative.
1 parent d5be3b7 commit ef428a2

1 file changed

Lines changed: 11 additions & 7 deletions

File tree

Doc/lib/libstdtypes.tex

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -839,15 +839,15 @@ \subsubsection{Mutable Sequence Types \label{typesseq-mutable}}
839839
{return smallest \var{i} such that \code{\var{s}[\var{i}] == \var{x}}}{(3)}
840840
\lineiii{\var{s}.insert(\var{i}, \var{x})}
841841
{same as \code{\var{s}[\var{i}:\var{i}] = [\var{x}]}
842-
if \code{\var{i} >= 0}}{}
842+
if \code{\var{i} >= 0}}{(4)}
843843
\lineiii{\var{s}.pop(\optional{\var{i}})}
844-
{same as \code{\var{x} = \var{s}[\var{i}]; del \var{s}[\var{i}]; return \var{x}}}{(4)}
844+
{same as \code{\var{x} = \var{s}[\var{i}]; del \var{s}[\var{i}]; return \var{x}}}{(5)}
845845
\lineiii{\var{s}.remove(\var{x})}
846846
{same as \code{del \var{s}[\var{s}.index(\var{x})]}}{(3)}
847847
\lineiii{\var{s}.reverse()}
848-
{reverses the items of \var{s} in place}{(5)}
848+
{reverses the items of \var{s} in place}{(6)}
849849
\lineiii{\var{s}.sort(\optional{\var{cmpfunc}})}
850-
{sort the items of \var{s} in place}{(5), (6)}
850+
{sort the items of \var{s} in place}{(6), (7)}
851851
\end{tableiii}
852852
\indexiv{operations on}{mutable}{sequence}{types}
853853
\indexiii{operations on}{sequence}{types}
@@ -874,16 +874,20 @@ \subsubsection{Mutable Sequence Types \label{typesseq-mutable}}
874874
\item[(3)] Raises \exception{ValueError} when \var{x} is not found in
875875
\var{s}.
876876

877-
\item[(4)] The \method{pop()} method is only supported by the list and
877+
\item[(4)] When a negative index is passed as the first parameter to
878+
the \method{insert()} method, the new element is prepended to the
879+
sequence.
880+
881+
\item[(5)] The \method{pop()} method is only supported by the list and
878882
array types. The optional argument \var{i} defaults to \code{-1},
879883
so that by default the last item is removed and returned.
880884

881-
\item[(5)] The \method{sort()} and \method{reverse()} methods modify the
885+
\item[(6)] The \method{sort()} and \method{reverse()} methods modify the
882886
list in place for economy of space when sorting or reversing a large
883887
list. To remind you that they operate by side effect, they don't return
884888
the sorted or reversed list.
885889

886-
\item[(6)] The \method{sort()} method takes an optional argument
890+
\item[(7)] The \method{sort()} method takes an optional argument
887891
specifying a comparison function of two arguments (list items) which
888892
should return a negative, zero or positive number depending on whether
889893
the first argument is considered smaller than, equal to, or larger

0 commit comments

Comments
 (0)