Funkce iter() v Pythonu
Příklad
Vytvořte objekt iterátoru a vytiskněte položky:
x = iter(["apple", "banana", "cherry"])
print(next(x))
print(next(x))
print(next(x))
Definice a použití
Funkce iter()
vrací objekt iterátoru.
Syntax
iter(object, sentinel)
Hodnoty parametrů
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 |
Související stránky
Funkce reversed() vrací objekt obráceného iterátoru.