Python iter() Fungsi
Contoh
Buat objek iterator, dan cetak item:
x = iter(["apple", "banana", "cherry"])
print(next(x))
print(next(x))
print(next(x))
Definisi dan Penggunaan
Fungsi iter()
mengembalikan objek iterator.
Sintaksis
iter(object, sentinel)
Nilai Parameter
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 |
Halaman Terkait
Fungsi reversed() mengembalikan objek iterator terbalik.