Python iter() Funzione
Esempio
Crea un oggetto iteratore e stampa gli elementi:
x = iter(["apple", "banana", "cherry"])
print(next(x))
print(next(x))
print(next(x))
Definizione e utilizzo
La iter()
funzione restituisce un oggetto iteratore.
Sintassi
iter(object, sentinel)
Valori dei parametri
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 |
Pagine correlate
La funzione reversed() restituisce un oggetto iteratore invertito.