Iterator Objects

Python provides two general-purpose iterator objects. The first, a sequenceiterator, works with an arbitrary sequence supporting the__getitem__()method. The second works with a callable object and a sentinel value, callingthe callable for each item in the sequence, and ending the iteration when thesentinel value is returned.

PyTypeObjectPySeqIter_Type
Μέρος τουΣταθερό ABI.

Type object for iterator objects returned byPySeqIter_New() and theone-argument form of theiter() built-in function for built-in sequencetypes.

intPySeqIter_Check(PyObject*op)

Return true if the type ofop isPySeqIter_Type. This functionalways succeeds.

PyObject*PySeqIter_New(PyObject*seq)
Επιστρεφόμενη τιμή: New reference. Μέρος τουΣταθερό ABI.

Return an iterator that works with a general sequence object,seq. Theiteration ends when the sequence raisesIndexError for the subscriptingoperation.

PyTypeObjectPyCallIter_Type
Μέρος τουΣταθερό ABI.

Type object for iterator objects returned byPyCallIter_New() and thetwo-argument form of theiter() built-in function.

intPyCallIter_Check(PyObject*op)

Return true if the type ofop isPyCallIter_Type. Thisfunction always succeeds.

PyObject*PyCallIter_New(PyObject*callable,PyObject*sentinel)
Επιστρεφόμενη τιμή: New reference. Μέρος τουΣταθερό ABI.

Return a new iterator. The first parameter,callable, can be any Pythoncallable object that can be called with no parameters; each call to it shouldreturn the next item in the iteration. Whencallable returns a value equal tosentinel, the iteration will be terminated.

Range Objects

PyTypeObjectPyRange_Type
Μέρος τουΣταθερό ABI.

The type object forrange objects.

intPyRange_Check(PyObject*o)

Return true if the objecto is an instance of arange object.This function always succeeds.

Builtin Iterator Types

These are built-in iteration types that are included in Python’s C API, butprovide no additional functions. They are here for completeness.

C type

Python type

PyTypeObjectPyEnum_Type
Μέρος τουΣταθερό ABI.

enumerate

PyTypeObjectPyFilter_Type
Μέρος τουΣταθερό ABI.

filter

PyTypeObjectPyMap_Type
Μέρος τουΣταθερό ABI.

map

PyTypeObjectPyReversed_Type
Μέρος τουΣταθερό ABI.

reversed

PyTypeObjectPyZip_Type
Μέρος τουΣταθερό ABI.

zip

Other Iterator Objects

PyTypeObjectPyByteArrayIter_Type
Μέρος τουΣταθερό ABI.
PyTypeObjectPyBytesIter_Type
Μέρος τουΣταθερό ABI.
PyTypeObjectPyListIter_Type
Μέρος τουΣταθερό ABI.
PyTypeObjectPyListRevIter_Type
Μέρος τουΣταθερό ABI.
PyTypeObjectPySetIter_Type
Μέρος τουΣταθερό ABI.
PyTypeObjectPyTupleIter_Type
Μέρος τουΣταθερό ABI.
PyTypeObjectPyRangeIter_Type
Μέρος τουΣταθερό ABI.
PyTypeObjectPyLongRangeIter_Type
Μέρος τουΣταθερό ABI.
PyTypeObjectPyDictIterKey_Type
Μέρος τουΣταθερό ABI.
PyTypeObjectPyDictRevIterKey_Type
Μέρος τουΣταθερό ABI από την έκδοση 3.8.
PyTypeObjectPyDictIterValue_Type
Μέρος τουΣταθερό ABI.
PyTypeObjectPyDictRevIterValue_Type
Μέρος τουΣταθερό ABI από την έκδοση 3.8.
PyTypeObjectPyDictIterItem_Type
Μέρος τουΣταθερό ABI.
PyTypeObjectPyDictRevIterItem_Type
Μέρος τουΣταθερό ABI από την έκδοση 3.8.
PyTypeObjectPyODictIter_Type

Type objects for iterators of various built-in objects.

Do not create instances of these directly; prefer callingPyObject_GetIter() instead.

Note that there is no guarantee that a given built-in type uses a given iteratortype. For example, iterating overrange will use one of two iteratortypes depending on the size of the range. Other types may start using asimilar scheme in the future, without warning.