mirror of
https://github.com/python/cpython.git
synced 2025-08-02 16:13:13 +00:00
Split combined code/doctest code blocks in two blocks, to enable proper highlighting.
This commit is contained in:
parent
e97f14c1bb
commit
da623ed9f4
1 changed files with 5 additions and 2 deletions
|
@ -730,7 +730,6 @@ built-in function; this example shows how it all works::
|
||||||
>>> next(it)
|
>>> next(it)
|
||||||
'c'
|
'c'
|
||||||
>>> next(it)
|
>>> next(it)
|
||||||
|
|
||||||
Traceback (most recent call last):
|
Traceback (most recent call last):
|
||||||
File "<stdin>", line 1, in ?
|
File "<stdin>", line 1, in ?
|
||||||
next(it)
|
next(it)
|
||||||
|
@ -742,7 +741,7 @@ returns an object with a :meth:`__next__` method. If the class defines
|
||||||
:meth:`__next__`, then :meth:`__iter__` can just return ``self``::
|
:meth:`__next__`, then :meth:`__iter__` can just return ``self``::
|
||||||
|
|
||||||
class Reverse:
|
class Reverse:
|
||||||
"Iterator for looping over a sequence backwards"
|
"""Iterator for looping over a sequence backwards."""
|
||||||
def __init__(self, data):
|
def __init__(self, data):
|
||||||
self.data = data
|
self.data = data
|
||||||
self.index = len(data)
|
self.index = len(data)
|
||||||
|
@ -754,6 +753,8 @@ returns an object with a :meth:`__next__` method. If the class defines
|
||||||
self.index = self.index - 1
|
self.index = self.index - 1
|
||||||
return self.data[self.index]
|
return self.data[self.index]
|
||||||
|
|
||||||
|
::
|
||||||
|
|
||||||
>>> rev = Reverse('spam')
|
>>> rev = Reverse('spam')
|
||||||
>>> iter(rev)
|
>>> iter(rev)
|
||||||
<__main__.Reverse object at 0x00A1DB50>
|
<__main__.Reverse object at 0x00A1DB50>
|
||||||
|
@ -782,6 +783,8 @@ easy to create::
|
||||||
for index in range(len(data)-1, -1, -1):
|
for index in range(len(data)-1, -1, -1):
|
||||||
yield data[index]
|
yield data[index]
|
||||||
|
|
||||||
|
::
|
||||||
|
|
||||||
>>> for char in reverse('golf'):
|
>>> for char in reverse('golf'):
|
||||||
... print(char)
|
... print(char)
|
||||||
...
|
...
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue