summaryrefslogtreecommitdiffstats
path: root/Doc/tutorial
diff options
context:
space:
mode:
authorMariatta <Mariatta@users.noreply.github.com>2017-02-26 06:35:39 (GMT)
committerGitHub <noreply@github.com>2017-02-26 06:35:39 (GMT)
commit4c784632f7cb5ede6df4b1b20cdfae155069a81b (patch)
treedcb3ceddebebd0fa7872a73da1e83b5ccc315fb8 /Doc/tutorial
parent5023686f7ee69e9da07cda4b7da6691f19892111 (diff)
downloadcpython-4c784632f7cb5ede6df4b1b20cdfae155069a81b.zip
cpython-4c784632f7cb5ede6df4b1b20cdfae155069a81b.tar.gz
cpython-4c784632f7cb5ede6df4b1b20cdfae155069a81b.tar.bz2
[3.5] Fix small typos in introduction and datastructures of tutorial (GH-272) (GH-299)
(cherry picked from commit 5bd5b9d81322d2cb6edd5f3804a347f8b2e65a15) (cherry picked from commit 8c5e190d360b9f1a08c9fff249ae80d9c18007d5) (cherry picked from commit 53c1892dc3de1de612b1cf95dc7bf09f82c1babf)
Diffstat (limited to 'Doc/tutorial')
-rw-r--r--Doc/tutorial/datastructures.rst59
-rw-r--r--Doc/tutorial/introduction.rst2
2 files changed, 32 insertions, 29 deletions
diff --git a/Doc/tutorial/datastructures.rst b/Doc/tutorial/datastructures.rst
index b39bdf4..6140ece 100644
--- a/Doc/tutorial/datastructures.rst
+++ b/Doc/tutorial/datastructures.rst
@@ -22,11 +22,11 @@ objects:
Add an item to the end of the list. Equivalent to ``a[len(a):] = [x]``.
-.. method:: list.extend(L)
+.. method:: list.extend(iterable)
:noindex:
- Extend the list by appending all the items in the given list. Equivalent to
- ``a[len(a):] = L``.
+ Extend the list by appending all the items from the iterable. Equivalent to
+ ``a[len(a):] = iterable``.
.. method:: list.insert(i, x)
@@ -60,11 +60,16 @@ objects:
Remove all items from the list. Equivalent to ``del a[:]``.
-.. method:: list.index(x)
+.. method:: list.index(x[, start[, end]])
:noindex:
- Return the index in the list of the first item whose value is *x*. It is an
- error if there is no such item.
+ Return zero-based index in the list of the first item whose value is *x*.
+ Raises a :exc:`ValueError` if there is no such item.
+
+ The optional arguments *start* and *end* are interpreted as in the slice
+ notation and are used to limit the search to a particular subsequence of
+ the list. The returned index is computed relative to the beginning of the full
+ sequence rather than the *start* argument.
.. method:: list.count(x)
@@ -94,28 +99,26 @@ objects:
An example that uses most of the list methods::
- >>> a = [66.25, 333, 333, 1, 1234.5]
- >>> print(a.count(333), a.count(66.25), a.count('x'))
- 2 1 0
- >>> a.insert(2, -1)
- >>> a.append(333)
- >>> a
- [66.25, 333, -1, 333, 1, 1234.5, 333]
- >>> a.index(333)
- 1
- >>> a.remove(333)
- >>> a
- [66.25, -1, 333, 1, 1234.5, 333]
- >>> a.reverse()
- >>> a
- [333, 1234.5, 1, 333, -1, 66.25]
- >>> a.sort()
- >>> a
- [-1, 1, 66.25, 333, 333, 1234.5]
- >>> a.pop()
- 1234.5
- >>> a
- [-1, 1, 66.25, 333, 333]
+ >>> fruits = ['orange', 'apple', 'pear', 'banana', 'kiwi', 'apple', 'banana']
+ >>> fruits.count('apple')
+ 2
+ >>> fruits.count('tangerine')
+ 0
+ >>> fruits.index('banana')
+ 3
+ >>> fruits.index('banana', 4) # Find next banana starting a position 4
+ 6
+ >>> fruits.reverse()
+ >>> fruits
+ ['banana', 'apple', 'kiwi', 'banana', 'pear', 'apple', 'orange']
+ >>> fruits.append('grape')
+ >>> fruits
+ ['banana', 'apple', 'kiwi', 'banana', 'pear', 'apple', 'orange', 'grape']
+ >>> fruits.sort()
+ >>> fruits
+ ['apple', 'apple', 'banana', 'banana', 'grape', 'kiwi', 'orange', 'pear']
+ >>> fruits.pop()
+ 'pear'
You might have noticed that methods like ``insert``, ``remove`` or ``sort`` that
only modify the list have no return value printed -- they return the default
diff --git a/Doc/tutorial/introduction.rst b/Doc/tutorial/introduction.rst
index 2140329..af277ce 100644
--- a/Doc/tutorial/introduction.rst
+++ b/Doc/tutorial/introduction.rst
@@ -356,7 +356,7 @@ The built-in function :func:`len` returns the length of a string::
Information about string formatting with :meth:`str.format`.
:ref:`old-string-formatting`
- The old formatting operations invoked when strings and Unicode strings are
+ The old formatting operations invoked when strings are
the left operand of the ``%`` operator are described in more detail here.