diff options
author | Daniel Stutzbach <daniel@stutzbachenterprises.com> | 2010-09-13 21:16:29 (GMT) |
---|---|---|
committer | Daniel Stutzbach <daniel@stutzbachenterprises.com> | 2010-09-13 21:16:29 (GMT) |
commit | 9f0cbf1c727f7de884c392176ab4f19a49924c9b (patch) | |
tree | fae5d3d7348ee4b9966e87dd14c5c4b381e77479 /Doc | |
parent | e4d6317c8725f9f341c6f2dd628e3b3ac79ef309 (diff) | |
download | cpython-9f0cbf1c727f7de884c392176ab4f19a49924c9b.zip cpython-9f0cbf1c727f7de884c392176ab4f19a49924c9b.tar.gz cpython-9f0cbf1c727f7de884c392176ab4f19a49924c9b.tar.bz2 |
Issue #9213: Add index and count methods to range objects, needed to
meet the API of the collections.Sequence ABC.
Diffstat (limited to 'Doc')
-rw-r--r-- | Doc/library/stdtypes.rst | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/Doc/library/stdtypes.rst b/Doc/library/stdtypes.rst index fa895cd..3a79862 100644 --- a/Doc/library/stdtypes.rst +++ b/Doc/library/stdtypes.rst @@ -1554,9 +1554,23 @@ looping. The advantage of the :class:`range` type is that an :class:`range` object will always take the same amount of memory, no matter the size of the range it represents. There are no consistent performance advantages. -Range objects have very little behavior: they only support indexing, iteration, -and the :func:`len` function. +Range objects have relatively little behavior: they support indexing, +iteration, the :func:`len` function, and the following methods. +.. method:: range.count(x) + + Return the number of *i*'s for which ``s[i] == x``. Normally the + result will be 0 or 1, but it could be greater if *x* defines an + unusual equality function. + + .. versionadded:: 3.2 + +.. method:: range.index(x) + + Return the smallest *i* such that ``s[i] == x``. Raises + :exc:`ValueError` when *x* is not in the range. + + .. versionadded:: 3.2 .. _typesseq-mutable: |