Python iter() Function

Python 内置函数Python Built-in Functions


Description

iter()This function is used to generate an iterator.

Syntax

The following is the syntax of the iter() method:

iter(object[, sentinel])

Parameters

  • object -- A collection object that supports iteration.
  • sentinel -- If the second parameter is passed, the object parameter must be a callable object (such as a function). In this case, iter creates an iterator object. Each time the __next__() method of this iterator object is called, object is called.
  • Open mode

Return Value

An iterator object.

Examples

>>>lst = [1, 2, 3] >>> for i in iter(lst): ... print(i) ... 1 2 3

Python 内置函数Python Built-in Functions

Other Extensions