diff options
author | Benjamin Peterson <benjamin@python.org> | 2009-03-17 20:29:51 (GMT) |
---|---|---|
committer | Benjamin Peterson <benjamin@python.org> | 2009-03-17 20:29:51 (GMT) |
commit | ed3558b3343d3af563829693483b28a4003711c8 (patch) | |
tree | d100585f811b3abf4b28a23ff40392d61d91dade | |
parent | b065e52bc284c2c28a967c4e82aa7ece6d09c562 (diff) | |
download | cpython-ed3558b3343d3af563829693483b28a4003711c8.zip cpython-ed3558b3343d3af563829693483b28a4003711c8.tar.gz cpython-ed3558b3343d3af563829693483b28a4003711c8.tar.bz2 |
I thought this was begging for an example
-rw-r--r-- | Doc/library/functions.rst | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/Doc/library/functions.rst b/Doc/library/functions.rst index bad9848..427f864 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 + <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 |