[Python-checkins] cpython (3.6): Issue 28587: list.index documentation missing start and stop arguments.
raymond.hettinger
python-checkins at python.org
Mon Nov 21 18:13:44 EST 2016
https://hg.python.org/cpython/rev/62c16fafa7d4
changeset: 105311:62c16fafa7d4
branch: 3.6
parent: 105309:a40159071359
user: Raymond Hettinger <python at rcn.com>
date: Mon Nov 21 15:12:54 2016 -0800
summary:
Issue 28587: list.index documentation missing start and stop arguments. (Contributed by Mariatta Wijaya.)
files:
Doc/tutorial/datastructures.rst | 13 ++++++++++---
1 files changed, 10 insertions(+), 3 deletions(-)
diff --git a/Doc/tutorial/datastructures.rst b/Doc/tutorial/datastructures.rst
--- a/Doc/tutorial/datastructures.rst
+++ b/Doc/tutorial/datastructures.rst
@@ -60,11 +60,16 @@
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
+ *x*. The returned index is computed relative to the beginning of the full
+ sequence rather than the *start* argument.
.. method:: list.count(x)
@@ -103,6 +108,8 @@
[66.25, 333, -1, 333, 1, 1234.5, 333]
>>> a.index(333)
1
+ >>> a.index(333, 2) # search for 333 starting at index 2
+ 2
>>> a.remove(333)
>>> a
[66.25, -1, 333, 1, 1234.5, 333]
--
Repository URL: https://hg.python.org/cpython
More information about the Python-checkins
mailing list