mirror of https://github.com/python/cpython
Split combined code/doctest code blocks in two blocks, to enable proper highlighting.
This commit is contained in:
parent
f9860c8298
commit
12b8fcfc45
|
@ -687,7 +687,6 @@ This example shows how it all works::
|
|||
>>> it.next()
|
||||
'c'
|
||||
>>> it.next()
|
||||
|
||||
Traceback (most recent call last):
|
||||
File "<stdin>", line 1, in ?
|
||||
it.next()
|
||||
|
@ -699,7 +698,7 @@ returns an object with a :meth:`next` method. If the class defines
|
|||
:meth:`next`, then :meth:`__iter__` can just return ``self``::
|
||||
|
||||
class Reverse:
|
||||
"Iterator for looping over a sequence backwards"
|
||||
"""Iterator for looping over a sequence backwards."""
|
||||
def __init__(self, data):
|
||||
self.data = data
|
||||
self.index = len(data)
|
||||
|
@ -711,6 +710,8 @@ returns an object with a :meth:`next` method. If the class defines
|
|||
self.index = self.index - 1
|
||||
return self.data[self.index]
|
||||
|
||||
::
|
||||
|
||||
>>> rev = Reverse('spam')
|
||||
>>> iter(rev)
|
||||
<__main__.Reverse object at 0x00A1DB50>
|
||||
|
@ -739,6 +740,8 @@ easy to create::
|
|||
for index in range(len(data)-1, -1, -1):
|
||||
yield data[index]
|
||||
|
||||
::
|
||||
|
||||
>>> for char in reverse('golf'):
|
||||
... print char
|
||||
...
|
||||
|
|
Loading…
Reference in New Issue