summaryrefslogtreecommitdiffstats
path: root/Doc/tutorial
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2021-08-17 21:42:50 (GMT)
committerGitHub <noreply@github.com>2021-08-17 21:42:50 (GMT)
commitf20f061cfaee639875a7a72926f3ad9cc4494ff9 (patch)
tree9b5a9d5bab5be1c93c70bfaed956ce7a9945ae80 /Doc/tutorial
parent826e059bb9b42e17bef2186938a2bd3f33610e69 (diff)
downloadcpython-f20f061cfaee639875a7a72926f3ad9cc4494ff9.zip
cpython-f20f061cfaee639875a7a72926f3ad9cc4494ff9.tar.gz
cpython-f20f061cfaee639875a7a72926f3ad9cc4494ff9.tar.bz2
introduce omitted index default before using it (GH-27775) (GH-27802)
(cherry picked from commit 599f5c8481ca258ca3a5d13eaee7d07a9103b5f2) Co-authored-by: Jefferson Oliveira <jefferson.dev.insights@gmail.com>
Diffstat (limited to 'Doc/tutorial')
-rw-r--r--Doc/tutorial/introduction.rst16
1 files changed, 8 insertions, 8 deletions
diff --git a/Doc/tutorial/introduction.rst b/Doc/tutorial/introduction.rst
index 4613cf7..8763626 100644
--- a/Doc/tutorial/introduction.rst
+++ b/Doc/tutorial/introduction.rst
@@ -269,14 +269,6 @@ to obtain individual characters, *slicing* allows you to obtain substring::
>>> word[2:5] # characters from position 2 (included) to 5 (excluded)
'tho'
-Note how the start is always included, and the end always excluded. This
-makes sure that ``s[:i] + s[i:]`` is always equal to ``s``::
-
- >>> word[:2] + word[2:]
- 'Python'
- >>> word[:4] + word[4:]
- 'Python'
-
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. ::
@@ -287,6 +279,14 @@ omitted second index defaults to the size of the string being sliced. ::
>>> word[-2:] # characters from the second-last (included) to the end
'on'
+Note how the start is always included, and the end always excluded. This
+makes sure that ``s[:i] + s[i:]`` is always equal to ``s``::
+
+ >>> word[:2] + word[2:]
+ 'Python'
+ >>> word[:4] + word[4:]
+ 'Python'
+
One way to remember how slices work is to think of the indices as pointing
*between* characters, with the left edge of the first character numbered 0.
Then the right edge of the last character of a string of *n* characters has