summaryrefslogtreecommitdiffstats
path: root/Doc/tutorial/classes.rst
diff options
context:
space:
mode:
Diffstat (limited to 'Doc/tutorial/classes.rst')
-rw-r--r--Doc/tutorial/classes.rst9
1 files changed, 6 insertions, 3 deletions
diff --git a/Doc/tutorial/classes.rst b/Doc/tutorial/classes.rst
index 82735df..a328ab2 100644
--- a/Doc/tutorial/classes.rst
+++ b/Doc/tutorial/classes.rst
@@ -717,7 +717,7 @@ object that defines the method :meth:`__next__` which accesses elements in the
container one at a time. When there are no more elements, :meth:`__next__`
raises a :exc:`StopIteration` exception which tells the :keyword:`for` loop to
terminate. You can call the :meth:`__next__` method using the :func:`next`
-builtin; this example shows how it all works::
+built-in function; this example shows how it all works::
>>> s = 'abc'
>>> it = iter(s)
@@ -730,7 +730,6 @@ builtin; 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)
...