Objetos Iteradores¶
O Python fornece dois objetos iteradores de propósito geral. O primeiro, um iterador de sequência, trabalha com uma sequência arbitrária suportando o método __getitem__(). O segundo trabalha com um objeto chamável e um valor de sentinela, chamando o chamável para cada item na sequência e finalizando a iteração quando o valor de sentinela é retornado.
-
PyTypeObject PySeqIter_Type¶
- Parte da ABI Estável.
Objeto de tipo para objetos iteradores retornados por
PySeqIter_New()e a forma de um argumento da função embutidaiter()para os tipos de sequência embutidos.
-
int PySeqIter_Check(PyObject *op)¶
Retorna true se o tipo de op for
PySeqIter_Type. Esta função sempre é bem-sucedida.
-
PyObject *PySeqIter_New(PyObject *seq)¶
- Retorna valor: Nova referência. Parte da ABI Estável.
Retorna um iterador que funcione com um objeto de sequência geral, seq. A iteração termina quando a sequência levanta
IndexErrorpara a operação de assinatura.
-
PyTypeObject PyCallIter_Type¶
- Parte da ABI Estável.
Objeto de tipo para objetos iteradores retornados por
PyCallIter_New()e a forma de dois argumentos da função embutidaiter().
-
int PyCallIter_Check(PyObject *op)¶
Retorna true se o tipo de op for
PyCallIter_Type. Esta função sempre é bem-sucedida.
-
PyObject *PyCallIter_New(PyObject *callable, PyObject *sentinel)¶
- Retorna valor: Nova referência. Parte da ABI Estável.
Retorna um novo iterador. O primeiro parâmetro, callable, pode ser qualquer objeto chamável do Python que possa ser chamado sem parâmetros; cada chamada deve retornar o próximo item na iteração. Quando callable retorna um valor igual a sentinel, a iteração será encerrada.
Range Objects¶
-
PyTypeObject PyRange_Type¶
- Parte da ABI Estável.
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¶
- Parte da ABI Estável.
-
PyTypeObject PyBytesIter_Type¶
- Parte da ABI Estável.
-
PyTypeObject PyListIter_Type¶
- Parte da ABI Estável.
-
PyTypeObject PyListRevIter_Type¶
- Parte da ABI Estável.
-
PyTypeObject PySetIter_Type¶
- Parte da ABI Estável.
-
PyTypeObject PyTupleIter_Type¶
- Parte da ABI Estável.
-
PyTypeObject PyRangeIter_Type¶
- Parte da ABI Estável.
-
PyTypeObject PyLongRangeIter_Type¶
- Parte da ABI Estável.
-
PyTypeObject PyDictIterKey_Type¶
- Parte da ABI Estável.
-
PyTypeObject PyDictRevIterKey_Type¶
- Parte da ABI Estável desde a versão 3.8.
-
PyTypeObject PyDictIterValue_Type¶
- Parte da ABI Estável.
-
PyTypeObject PyDictRevIterValue_Type¶
- Parte da ABI Estável desde a versão 3.8.
-
PyTypeObject PyDictIterItem_Type¶
- Parte da ABI Estável.
-
PyTypeObject PyDictRevIterItem_Type¶
- Parte da ABI Estável desde a versão 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.