summaryrefslogtreecommitdiffstats
path: root/Doc/tut
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2003-03-12 04:46:52 (GMT)
committerRaymond Hettinger <python@rcn.com>2003-03-12 04:46:52 (GMT)
commit60de2e837fbbc14f68fca544e5c3288f5ba53c73 (patch)
tree572e60563c12077257ffaa74ca0b7c25d435213f /Doc/tut
parent83245b58280a7679da0fe7216f36353e44ddf859 (diff)
downloadcpython-60de2e837fbbc14f68fca544e5c3288f5ba53c73.zip
cpython-60de2e837fbbc14f68fca544e5c3288f5ba53c73.tar.gz
cpython-60de2e837fbbc14f68fca544e5c3288f5ba53c73.tar.bz2
SF bug #699237: Tutorial uses omitted slice indices before explaining them
Moved up the explanation of slice default arguments.
Diffstat (limited to 'Doc/tut')
-rw-r--r--Doc/tut/tut.tex22
1 files changed, 11 insertions, 11 deletions
diff --git a/Doc/tut/tut.tex b/Doc/tut/tut.tex
index a9fb325..71d3f60 100644
--- a/Doc/tut/tut.tex
+++ b/Doc/tut/tut.tex
@@ -640,6 +640,17 @@ separated by a colon.
'lp'
\end{verbatim}
+Slice indices have useful defaults; an omitted first index defaults to
+zero, an omitted second index defaults to the size of the string being
+sliced.
+
+\begin{verbatim}
+>>> word[:2] # The first two characters
+'He'
+>>> word[2:] # All but the first two characters
+'lpA'
+\end{verbatim}
+
Unlike a C string, Python strings cannot be changed. Assigning to an
indexed position in the string results in an error:
@@ -664,17 +675,6 @@ efficient:
'SplatA'
\end{verbatim}
-Slice indices have useful defaults; an omitted first index defaults to
-zero, an omitted second index defaults to the size of the string being
-sliced.
-
-\begin{verbatim}
->>> word[:2] # The first two characters
-'He'
->>> word[2:] # All but the first two characters
-'lpA'
-\end{verbatim}
-
Here's a useful invariant of slice operations:
\code{s[:i] + s[i:]} equals \code{s}.