Función Python iter()
Ejemplo
Cree un objeto iterador e imprima los elementos:
x = iter(["apple", "banana", "cherry"])
print(next(x))
print(next(x))
print(next(x))
Definición y uso
La iter()
función devuelve un objeto iterador.
Sintaxis
iter(object, sentinel)
Valores paramétricos
Parameter | Description |
---|---|
object | Required. An iterable object |
sentinel | Optional. If the object is a callable object the iteration will stop when the returned value is the same as the sentinel |
páginas relacionadas
La función reversed() devuelve un objeto iterador invertido.