From ed3558b3343d3af563829693483b28a4003711c8 Mon Sep 17 00:00:00 2001 From: Benjamin Peterson Date: Tue, 17 Mar 2009 20:29:51 +0000 Subject: [PATCH] I thought this was begging for an example --- Doc/library/functions.rst | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/Doc/library/functions.rst b/Doc/library/functions.rst index bad9848602d..427f864a37a 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