File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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+
643654Unlike a C string, Python strings cannot be changed. Assigning to an
644655indexed 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-
678678Here's a useful invariant of slice operations:
679679\code {s[:i] + s[i:]} equals \code {s}.
680680
You can’t perform that action at this time.
0 commit comments