diff --git a/Doc/tutorial/classes.rst b/Doc/tutorial/classes.rst index ed0e6557c20..5ee90677846 100644 --- a/Doc/tutorial/classes.rst +++ b/Doc/tutorial/classes.rst @@ -687,7 +687,6 @@ This example shows how it all works:: >>> it.next() 'c' >>> it.next() - Traceback (most recent call last): File "", 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 ...