From: Benjamin Peterson Date: Tue, 17 Mar 2009 20:29:51 +0000 (+0000) Subject: I thought this was begging for an example X-Git-Tag: v2.7a1~1847 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=ed3558b3343d3af563829693483b28a4003711c8;p=python I thought this was begging for an example --- diff --git a/Doc/library/functions.rst b/Doc/library/functions.rst index bad9848602..427f864a37 100644 --- a/Doc/library/functions.rst +++ b/Doc/library/functions.rst @@ -596,6 +596,25 @@ available. They are listed here in alphabetical order. its :meth:`next` method; if the value returned is equal to *sentinel*, :exc:`StopIteration` will be raised, otherwise the value will be returned. + Example usage: :: + + >>> iterator = iter(range(10)) + >>> iterator + + >>> iterator.next() + 0 + >>> iterator.next() + 1 + >>> def my_generator(): + ... for i in range(10): + ... yield i + ... + >>> iterator = iter(my_generator().next, 7) + >>> iterator + + >>> list(iterator) + [0, 1, 2, 3, 4, 5, 6] + .. versionadded:: 2.2