mirror of https://github.com/python/cpython
Add reference to enumerate() to indices example.
This commit is contained in:
parent
5248103ef9
commit
34196c851a
|
@ -104,8 +104,8 @@ increment (even negative; sometimes this is called the 'step')::
|
||||||
>>> range(-10, -100, -30)
|
>>> range(-10, -100, -30)
|
||||||
[-10, -40, -70]
|
[-10, -40, -70]
|
||||||
|
|
||||||
To iterate over the indices of a sequence, combine :func:`range` and :func:`len`
|
To iterate over the indices of a sequence, you can combine :func:`range` and
|
||||||
as follows::
|
:func:`len` as follows::
|
||||||
|
|
||||||
>>> a = ['Mary', 'had', 'a', 'little', 'lamb']
|
>>> a = ['Mary', 'had', 'a', 'little', 'lamb']
|
||||||
>>> for i in range(len(a)):
|
>>> for i in range(len(a)):
|
||||||
|
@ -117,6 +117,9 @@ as follows::
|
||||||
3 little
|
3 little
|
||||||
4 lamb
|
4 lamb
|
||||||
|
|
||||||
|
In most such cases, however, it is convenient to use the :func:`enumerate`
|
||||||
|
function, see :ref:`tut-loopidioms`.
|
||||||
|
|
||||||
|
|
||||||
.. _tut-break:
|
.. _tut-break:
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue