diff options
author | Raymond Hettinger <python@rcn.com> | 2016-11-21 15:13:38 -0800 |
---|---|---|
committer | Raymond Hettinger <python@rcn.com> | 2016-11-21 15:13:38 -0800 |
commit | 1f56e25412dbb538c1ea707daddefe18ccd1adff (patch) | |
tree | 1c316c2d205893b9b7681a7d1aa6575c657a7bdf /Doc/tutorial | |
parent | 4878d001b173788c9dceb756c6e76aa5ed111967 (diff) | |
parent | 7f946195558b3681b81707c52b721d067373acee (diff) | |
download | cpython-git-1f56e25412dbb538c1ea707daddefe18ccd1adff.tar.gz |
merge
Diffstat (limited to 'Doc/tutorial')
-rw-r--r-- | Doc/tutorial/datastructures.rst | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/Doc/tutorial/datastructures.rst b/Doc/tutorial/datastructures.rst index b39bdf4dfb..83a1f9bef1 100644 --- a/Doc/tutorial/datastructures.rst +++ b/Doc/tutorial/datastructures.rst @@ -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 + *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 @@ An example that uses most of the list methods:: [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] |