Skip to content

Latest commit

 

History

History
52 lines (31 loc) · 1.69 KB

iterator.rst

File metadata and controls

52 lines (31 loc) · 1.69 KB

Iterator Objects

Python provides two general-purpose iterator objects. The first, a sequence iterator, works with an arbitrary sequence supporting the :meth:`~object.__getitem__` method. The second works with a callable object and a sentinel value, calling the callable for each item in the sequence, and ending the iteration when the sentinel value is returned.

.. c:var:: PyTypeObjectPySeqIter_TypeTypeobjectforiteratorobjectsreturnedby :c:func:`PySeqIter_New` andtheone-argumentformofthe :func:`iter` built-infunctionforbuilt-insequencetypes. 
.. c:function:: intPySeqIter_Check(PyObject*op) Returntrueifthetypeof*op*is :c:data:`PySeqIter_Type`. Thisfunctionalwayssucceeds. 
.. c:function:: PyObject*PySeqIter_New(PyObject*seq) Returnaniteratorthatworkswithageneralsequenceobject, *seq*. Theiterationendswhenthesequenceraises :exc:`IndexError` forthesubscriptingoperation. 
.. c:var:: PyTypeObjectPyCallIter_TypeTypeobjectforiteratorobjectsreturnedby :c:func:`PyCallIter_New` andthetwo-argumentformofthe :func:`iter` built-infunction. 
.. c:function:: intPyCallIter_Check(PyObject*op) Returntrueifthetypeof*op*is :c:data:`PyCallIter_Type`. Thisfunctionalwayssucceeds. 
.. c:function:: PyObject*PyCallIter_New(PyObject*callable, PyObject*sentinel) Returnanewiterator. Thefirstparameter, *callable*, canbeanyPythoncallableobjectthatcanbecalledwithnoparameters; eachcalltoitshouldreturnthenextitemintheiteration. When*callable*returnsavalueequalto*sentinel*, theiterationwillbeterminated.
close