Kaydet (Commit) 12b8fcfc authored tarafından Georg Brandl's avatar Georg Brandl

Split combined code/doctest code blocks in two blocks, to enable proper highlighting.

üst f9860c82
......@@ -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
...
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment