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

Skip to content

Commit 60de2e8

Browse files
committed
SF bug #699237: Tutorial uses omitted slice indices before explaining them
Moved up the explanation of slice default arguments.
1 parent 83245b5 commit 60de2e8

1 file changed

Lines changed: 11 additions & 11 deletions

File tree

Doc/tut/tut.tex

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -640,6 +640,17 @@ \subsection{Strings \label{strings}}
640640
'lp'
641641
\end{verbatim}
642642

643+
Slice indices have useful defaults; an omitted first index defaults to
644+
zero, an omitted second index defaults to the size of the string being
645+
sliced.
646+
647+
\begin{verbatim}
648+
>>> word[:2] # The first two characters
649+
'He'
650+
>>> word[2:] # All but the first two characters
651+
'lpA'
652+
\end{verbatim}
653+
643654
Unlike a C string, Python strings cannot be changed. Assigning to an
644655
indexed position in the string results in an error:
645656

@@ -664,17 +675,6 @@ \subsection{Strings \label{strings}}
664675
'SplatA'
665676
\end{verbatim}
666677

667-
Slice indices have useful defaults; an omitted first index defaults to
668-
zero, an omitted second index defaults to the size of the string being
669-
sliced.
670-
671-
\begin{verbatim}
672-
>>> word[:2] # The first two characters
673-
'He'
674-
>>> word[2:] # All but the first two characters
675-
'lpA'
676-
\end{verbatim}
677-
678678
Here's a useful invariant of slice operations:
679679
\code{s[:i] + s[i:]} equals \code{s}.
680680

0 commit comments

Comments
 (0)