diff options
author | Georg Brandl <georg@python.org> | 2011-05-01 20:37:23 (GMT) |
---|---|---|
committer | Georg Brandl <georg@python.org> | 2011-05-01 20:37:23 (GMT) |
commit | da623ed9f43a13bc285a7e29ae8774d29c481332 (patch) | |
tree | bf6fdba1eb68b8d9b550ee881382e1a7db1acac0 /Doc/tutorial/classes.rst | |
parent | e97f14c1bbd02d385f30f769c350731e2f2e251c (diff) | |
download | cpython-da623ed9f43a13bc285a7e29ae8774d29c481332.zip cpython-da623ed9f43a13bc285a7e29ae8774d29c481332.tar.gz cpython-da623ed9f43a13bc285a7e29ae8774d29c481332.tar.bz2 |
Split combined code/doctest code blocks in two blocks, to enable proper highlighting.
Diffstat (limited to 'Doc/tutorial/classes.rst')
-rw-r--r-- | Doc/tutorial/classes.rst | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/Doc/tutorial/classes.rst b/Doc/tutorial/classes.rst index 576ef3a..a328ab2 100644 --- a/Doc/tutorial/classes.rst +++ b/Doc/tutorial/classes.rst @@ -730,7 +730,6 @@ built-in function; this example shows how it all works:: >>> next(it) 'c' >>> next(it) - Traceback (most recent call last): File "<stdin>", line 1, in ? 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``:: 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) @@ -754,6 +753,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> @@ -782,6 +783,8 @@ easy to create:: for index in range(len(data)-1, -1, -1): yield data[index] +:: + >>> for char in reverse('golf'): ... print(char) ... |