[Python-checkins] r70438 - python/trunk/Doc/library/functions.rst
benjamin.peterson
python-checkins at python.org
Tue Mar 17 21:29:52 CET 2009
Author: benjamin.peterson
Date: Tue Mar 17 21:29:51 2009
New Revision: 70438
Log:
I thought this was begging for an example
Modified:
python/trunk/Doc/library/functions.rst
Modified: python/trunk/Doc/library/functions.rst
==============================================================================
--- python/trunk/Doc/library/functions.rst (original)
+++ python/trunk/Doc/library/functions.rst Tue Mar 17 21:29:51 2009
@@ -596,6 +596,25 @@
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
+ <listiterator object at 0x86b50>
+ >>> iterator.next()
+ 0
+ >>> iterator.next()
+ 1
+ >>> def my_generator():
+ ... for i in range(10):
+ ... yield i
+ ...
+ >>> iterator = iter(my_generator().next, 7)
+ >>> iterator
+ <callable-iterator object at 0x86bb0>
+ >>> list(iterator)
+ [0, 1, 2, 3, 4, 5, 6]
+
.. versionadded:: 2.2
More information about the Python-checkins
mailing list