@@ -433,6 +433,7 @@ \subsection{Sequence Types \label{typesseq}}
433433 \hline
434434 \lineiii {\var {s}[\var {i}]}{\var {i}'th item of \var {s}, origin 0}{(2)}
435435 \lineiii {\var {s}[\var {i}:\var {j}]}{slice of \var {s} from \var {i} to \var {j}}{(2), (3)}
436+ \lineiii {\var {s}[\var {i}:\var {j}:\var {k}]}{slice of \var {s} from \var {i} to \var {j} with step \var {k}}{(2), (4)}
436437 \hline
437438 \lineiii {len(\var {s})}{length of \var {s}}{}
438439 \lineiii {min(\var {s})}{smallest item of \var {s}}{}
@@ -446,6 +447,7 @@ \subsection{Sequence Types \label{typesseq}}
446447\indexii {repetition}{operation}
447448\indexii {subscript}{operation}
448449\indexii {slice}{operation}
450+ \indexii {extended slice}{operation}
449451\opindex {in}
450452\opindex {not in}
451453
@@ -492,6 +494,15 @@ \subsection{Sequence Types \label{typesseq}}
492494 \code {len(\var {s})}, use \code {len(\var {s})}. If \var {i} is omitted,
493495 use \code {0}. If \var {j} is omitted, use \code {len(\var {s})}. If
494496 \var {i} is greater than or equal to \var {j}, the slice is empty.
497+
498+ \item [(4)] The slice of \var {s} from \var {i} to \var {j} with step \var {k}
499+ is defined as the sequence of items with index \code {\var {x} =
500+ \var {i} + \var {n}*\var {k}} such that \var {n} \code {>=} \code {0} and
501+ \code {\var {i} <= \var {x} < \var {j}}. If \var {i} or \var {j} is
502+ greater than \code {len(\var {s})}, use \code {len(\var {s})}. If
503+ \var {i} or \var {j} are ommitted then they become `` end'' values
504+ (which end depends on the sign of \var {k}).
505+
495506\end {description }
496507
497508
@@ -875,31 +886,36 @@ \subsubsection{Mutable Sequence Types \label{typesseq-mutable}}
875886 {slice of \var {s} from \var {i} to \var {j} is replaced by \var {t}}{}
876887 \lineiii {del \var {s}[\var {i}:\var {j}]}
877888 {same as \code {\var {s}[\var {i}:\var {j}] = []}}{}
889+ \lineiii {\var {s}[\var {i}:\var {j}:\var {k}] = \var {t}}
890+ {the elements of \code {\var {s}[\var {i}:\var {j}:\var {k}]} are replaced by those of \var {t}}{(1)}
891+ \lineiii {del \var {s}[\var {i}:\var {j}:\var {k}]}
892+ {removes the elements of \code {\var {s}[\var {i}:\var {j}:\var {k}]} from the list}{}
878893 \lineiii {\var {s}.append(\var {x})}
879- {same as \code {\var {s}[len(\var {s}):len(\var {s})] = [\var {x}]}}{(1 )}
894+ {same as \code {\var {s}[len(\var {s}):len(\var {s})] = [\var {x}]}}{(2 )}
880895 \lineiii {\var {s}.extend(\var {x})}
881- {same as \code {\var {s}[len(\var {s}):len(\var {s})] = \var {x}}}{(2 )}
896+ {same as \code {\var {s}[len(\var {s}):len(\var {s})] = \var {x}}}{(3 )}
882897 \lineiii {\var {s}.count(\var {x})}
883898 {return number of \var {i}'s for which \code {\var {s}[\var {i}] == \var {x}}}{}
884899 \lineiii {\var {s}.index(\var {x})}
885- {return smallest \var {i} such that \code {\var {s}[\var {i}] == \var {x}}}{(3 )}
900+ {return smallest \var {i} such that \code {\var {s}[\var {i}] == \var {x}}}{(4 )}
886901 \lineiii {\var {s}.insert(\var {i}, \var {x})}
887902 {same as \code {\var {s}[\var {i}:\var {i}] = [\var {x}]}
888- if \code {\var {i} >= 0}}{(4 )}
903+ if \code {\var {i} >= 0}}{(5 )}
889904 \lineiii {\var {s}.pop(\optional {\var {i}})}
890- {same as \code {\var {x} = \var {s}[\var {i}]; del \var {s}[\var {i}]; return \var {x}}}{(5 )}
905+ {same as \code {\var {x} = \var {s}[\var {i}]; del \var {s}[\var {i}]; return \var {x}}}{(6 )}
891906 \lineiii {\var {s}.remove(\var {x})}
892- {same as \code {del \var {s}[\var {s}.index(\var {x})]}}{(3 )}
907+ {same as \code {del \var {s}[\var {s}.index(\var {x})]}}{(4 )}
893908 \lineiii {\var {s}.reverse()}
894- {reverses the items of \var {s} in place}{(6 )}
909+ {reverses the items of \var {s} in place}{(7 )}
895910 \lineiii {\var {s}.sort(\optional {\var {cmpfunc}})}
896- {sort the items of \var {s} in place}{(6 ), (7 )}
911+ {sort the items of \var {s} in place}{(7 ), (8 )}
897912\end {tableiii }
898913\indexiv {operations on}{mutable}{sequence}{types}
899914\indexiii {operations on}{sequence}{types}
900915\indexiii {operations on}{list}{type}
901916\indexii {subscript}{assignment}
902917\indexii {slice}{assignment}
918+ \indexii {extended slice}{assignment}
903919\stindex {del}
904920\withsubitem {(list method)}{
905921 \ttindex {append()}\ttindex {extend()}\ttindex {count()}\ttindex {index()}
@@ -908,32 +924,35 @@ \subsubsection{Mutable Sequence Types \label{typesseq-mutable}}
908924\noindent
909925Notes:
910926\begin {description }
911- \item [(1)] The C implementation of Python has historically accepted
927+ \item [(1)] \var {t} must have the same length as the slice it is
928+ replacing.
929+
930+ \item [(2)] The C implementation of Python has historically accepted
912931 multiple parameters and implicitly joined them into a tuple; this
913932 no longer works in Python 2.0. Use of this misfeature has been
914933 deprecated since Python 1.4.
915934
916- \item [(2 )] Raises an exception when \var {x} is not a list object. The
935+ \item [(3 )] Raises an exception when \var {x} is not a list object. The
917936 \method {extend()} method is experimental and not supported by
918937 mutable sequence types other than lists.
919938
920- \item [(3 )] Raises \exception {ValueError} when \var {x} is not found in
939+ \item [(4 )] Raises \exception {ValueError} when \var {x} is not found in
921940 \var {s}.
922941
923- \item [(4 )] When a negative index is passed as the first parameter to
942+ \item [(5 )] When a negative index is passed as the first parameter to
924943 the \method {insert()} method, the new element is prepended to the
925944 sequence.
926945
927- \item [(5 )] The \method {pop()} method is only supported by the list and
946+ \item [(6 )] The \method {pop()} method is only supported by the list and
928947 array types. The optional argument \var {i} defaults to \code {-1},
929948 so that by default the last item is removed and returned.
930949
931- \item [(6 )] The \method {sort()} and \method {reverse()} methods modify the
950+ \item [(7 )] The \method {sort()} and \method {reverse()} methods modify the
932951 list in place for economy of space when sorting or reversing a large
933952 list. To remind you that they operate by side effect, they don't return
934953 the sorted or reversed list.
935954
936- \item [(7 )] The \method {sort()} method takes an optional argument
955+ \item [(8 )] The \method {sort()} method takes an optional argument
937956 specifying a comparison function of two arguments (list items) which
938957 should return a negative, zero or positive number depending on whether
939958 the first argument is considered smaller than, equal to, or larger
0 commit comments