Python iter()関数
例
イテレータオブジェクトを作成し、アイテムを印刷します。
x = iter(["apple", "banana", "cherry"])
print(next(x))
print(next(x))
print(next(x))
定義と使用法
このiter()
関数はイテレータオブジェクトを返します。
構文
iter(object, sentinel)
パラメータ値
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 |
関連ページ
reverse ()関数は、逆イテレータオブジェクトを返します。