@@ -810,40 +810,41 @@ using two distinct methods; these are used to allow user-defined classes to
810
810
support iteration. Sequences, described below in more detail, always support
811
811
the iteration methods.
812
812
813
- One method needs to be defined for container objects to provide iteration
813
+ One method needs to be defined for container objects to provide :term: ` iterable `
814
814
support:
815
815
816
816
.. XXX duplicated in reference/datamodel!
817
817
818
818
.. method :: container.__iter__()
819
819
820
- Return an iterator object. The object is required to support the iterator
821
- protocol described below. If a container supports different types of
822
- iteration, additional methods can be provided to specifically request
820
+ Return an :term: ` iterator ` object. The object is required to support the
821
+ iterator protocol described below. If a container supports different types
822
+ of iteration, additional methods can be provided to specifically request
823
823
iterators for those iteration types. (An example of an object supporting
824
824
multiple forms of iteration would be a tree structure which supports both
825
825
breadth-first and depth-first traversal.) This method corresponds to the
826
- :c:member: `~PyTypeObject.tp_iter ` slot of the type structure for Python objects in the Python/C
827
- API.
826
+ :c:member: `~PyTypeObject.tp_iter ` slot of the type structure for Python
827
+ objects in the Python/C API.
828
828
829
829
The iterator objects themselves are required to support the following two
830
830
methods, which together form the :dfn: `iterator protocol `:
831
831
832
832
833
833
.. method :: iterator.__iter__()
834
834
835
- Return the iterator object itself. This is required to allow both containers
836
- and iterators to be used with the :keyword: `for ` and :keyword: `in ` statements.
837
- This method corresponds to the :c:member: `~PyTypeObject.tp_iter ` slot of the type structure for
838
- Python objects in the Python/C API.
835
+ Return the :term: `iterator ` object itself. This is required to allow both
836
+ containers and iterators to be used with the :keyword: `for ` and
837
+ :keyword: `in ` statements. This method corresponds to the
838
+ :c:member: `~PyTypeObject.tp_iter ` slot of the type structure for Python
839
+ objects in the Python/C API.
839
840
840
841
841
842
.. method :: iterator.__next__()
842
843
843
- Return the next item from the container . If there are no further items, raise
844
- the :exc: `StopIteration ` exception. This method corresponds to the
845
- :c:member: `~PyTypeObject.tp_iternext ` slot of the type structure for Python objects in the
846
- Python/C API.
844
+ Return the next item from the :term: ` iterator ` . If there are no further
845
+ items, raise the :exc: `StopIteration ` exception. This method corresponds to
846
+ the :c:member: `~PyTypeObject.tp_iternext ` slot of the type structure for
847
+ Python objects in the Python /C API.
847
848
848
849
Python defines several iterator objects to support iteration over general and
849
850
specific sequence types, dictionaries, and other more specialized forms. The
0 commit comments