Objek Iterator

Python provides two general-purpose iterator objects. The first, a sequence iterator, works with an arbitrary sequence supporting the __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.

PyTypeObject PySeqIter_Type
Part of the Stable ABI.

Tipe objek untuk objek iterator yang dikembalikan oleh PySeqIter_New() dan bentuk satu argumen dari fungsi bawaan iter() untuk tipe urutan bawaan.

int PySeqIter_Check(PyObject *op)

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

PyObject *PySeqIter_New(PyObject *seq)
Return value: New reference. Part of the Stable ABI.

Mengembalikan iterator yang bekerja dengan objek urutan umum, seq. Iterasi berakhir ketika urutan memunculkan IndexError untuk operasi berlangganan (subscripting).

PyTypeObject PyCallIter_Type
Part of the Stable ABI.

Tipe objek untuk objek iterator yang dikembalikan oleh PyCallIter_New() dan bentuk dua argumen dari fungsi bawaan iter() .

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)
Return value: New reference. Part of the Stable ABI.

Mengembalikan iterator baru. Parameter pertama, callable, dapat berupa objek Python callable apa saja yang bisa dipanggil tanpa parameter; setiap pemanggilan harus mengembalikan butir (item) berikutnya pada iterator. Ketika callable mengembalikan nilai sama dengan sentinel, perulangan akan dihentikan.