疊代器(Iterator)物件

Python 提供了兩種通用的疊代器 (iterator) 物件,第一種是序列疊代器 (sequence iterator),適用於支援 __getitem__() 方法的任意序列,第二種是與可呼叫 (callable) 物件和哨兵值 (sentinel value) 一起使用,會呼叫序列中的每個可呼叫物件,當回傳哨兵值時就結束疊代。

PyTypeObject PySeqIter_Type
穩定 ABI 的一部分.

此型別物件用於由 PySeqIter_New() 所回傳的疊代器物件以及用於內建序列型別的內建函式 iter() 的單引數形式。

int PySeqIter_Check(PyObject *op)

Return true if the type of op is PySeqIter_Type. This function always succeeds.

PyObject *PySeqIter_New(PyObject *seq)
回傳值:新的參照。穩定 ABI 的一部分.

Return an iterator that works with a general sequence object, seq. The iteration ends when the sequence raises IndexError for the subscripting operation.

PyTypeObject PyCallIter_Type
穩定 ABI 的一部分.

Type object for iterator objects returned by PyCallIter_New() and the two-argument form of the iter() built-in function.

int PyCallIter_Check(PyObject *op)

Return true if the type of op is PyCallIter_Type. This function always succeeds.

PyObject *PyCallIter_New(PyObject *callable, PyObject *sentinel)
回傳值:新的參照。穩定 ABI 的一部分.

Return a new iterator. The first parameter, callable, can be any Python callable object that can be called with no parameters; each call to it should return the next item in the iteration. When callable returns a value equal to sentinel, the iteration will be terminated.