イテレータオブジェクト (iterator object)¶
Python では二種類のイテレータオブジェクトを提供しています。一つ目はシーケンスイテレータで、 __getitem__() メソッドをサポートする任意のシーケンスを取り扱います。二つ目は呼び出し可能オブジェクトと番兵 (sentinel value) を扱い、シーケンス内の要素ごとに呼び出し可能オブジェクトを呼び出して、センチネル値が返されたときに反復処理を終了します。
-
PyTypeObject PySeqIter_Type¶
- 次に属します: Stable ABI.
PySeqIter_New()や、組み込みシーケンス型に対して 1 引数形式の組み込み関数iter()を呼び出したときに返される、イテレータオブジェクトの型オブジェクトです。
-
PyObject *PySeqIter_New(PyObject *seq)¶
- 戻り値: 新しい参照。 次に属します: Stable ABI.
一般的なシーケンスオブジェクト seq を扱うイテレータを返します。反復処理は、シーケンスが添字指定操作の際に
IndexErrorを返したときに終了します。
-
PyTypeObject PyCallIter_Type¶
- 次に属します: Stable ABI.
PyCallIter_New()や、組み込み関数iter()の 2 引数形式が返すイテレータオブジェクトの型オブジェクトです。
-
int PyCallIter_Check(PyObject *op)¶
op の型が
PyCallIter_Type型の場合に真を返します。この関数は常に成功します。
-
PyObject *PyCallIter_New(PyObject *callable, PyObject *sentinel)¶
- 戻り値: 新しい参照。 次に属します: Stable ABI.
新たなイテレータを返します。最初のパラメタ callable は引数なしで呼び出せる Python の呼び出し可能オブジェクトならなんでもかまいません; callable は、呼び出されるたびに次の反復処理対象オブジェクトを返さなければなりません。生成されたイテレータは、callable が sentinel に等しい値を返すと反復処理を終了します。
Range Objects¶
-
PyTypeObject PyRange_Type¶
- 次に属します: Stable ABI.
The type object for
rangeobjects.
Builtin Iterator Types¶
These are built-in iteration types that are included in Python's C API, but provide no additional functions. They are here for completeness.
C type |
Python type |
|---|---|
|
|
|
|
|
|
|
|
|
Other Iterator Objects¶
-
PyTypeObject PyByteArrayIter_Type¶
- 次に属します: Stable ABI.
-
PyTypeObject PyBytesIter_Type¶
- 次に属します: Stable ABI.
-
PyTypeObject PyListIter_Type¶
- 次に属します: Stable ABI.
-
PyTypeObject PyListRevIter_Type¶
- 次に属します: Stable ABI.
-
PyTypeObject PySetIter_Type¶
- 次に属します: Stable ABI.
-
PyTypeObject PyTupleIter_Type¶
- 次に属します: Stable ABI.
-
PyTypeObject PyRangeIter_Type¶
- 次に属します: Stable ABI.
-
PyTypeObject PyLongRangeIter_Type¶
- 次に属します: Stable ABI.
-
PyTypeObject PyDictIterKey_Type¶
- 次に属します: Stable ABI.
-
PyTypeObject PyDictRevIterKey_Type¶
- 次に属します: Stable ABI (バージョン 3.8 より).
-
PyTypeObject PyDictIterValue_Type¶
- 次に属します: Stable ABI.
-
PyTypeObject PyDictRevIterValue_Type¶
- 次に属します: Stable ABI (バージョン 3.8 より).
-
PyTypeObject PyDictIterItem_Type¶
- 次に属します: Stable ABI.
-
PyTypeObject PyDictRevIterItem_Type¶
- 次に属します: Stable ABI (バージョン 3.8 より).
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 iterator type. For example, iterating over
rangewill use one of two iterator types depending on the size of the range. Other types may start using a similar scheme in the future, without warning.