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 by
PySeqIter_New()and theone-argument form of theiter()built-in function for built-in sequencetypes.
- intPySeqIter_Check(PyObject*op)¶
Return true if the type ofop is
PySeqIter_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 raises
IndexErrorfor the subscriptingoperation.
- PyTypeObjectPyCallIter_Type¶
- Μέρος τουΣταθερό ABI.
Type object for iterator objects returned by
PyCallIter_New()and thetwo-argument form of theiter()built-in function.
- intPyCallIter_Check(PyObject*op)¶
Return true if the type ofop is
PyCallIter_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 for
rangeobjects.
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 |
|---|---|
| |
| |
| |
| |
|
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 calling
PyObject_GetIter()instead.Note that there is no guarantee that a given built-in type uses a given iteratortype. For example, iterating over
rangewill use one of two iteratortypes depending on the size of the range. Other types may start using asimilar scheme in the future, without warning.