This function returns an iteration sub-object. When the second argument does not appear, the parameter object should be a container that supports iterative protocols , that is, there is a __iter__ () function defined, or a sequence access protocol, which defines The __getitem__ () function of the object, otherwise the TypeError exception is returned. When the second parameter Sentinel appears, the parameter object should be a callable object that defines the __next__ () function, which throws an exception when the enumerated value equals the Sentinel . stopiteration .
Example:
#iter () s = ' software is the future of Shenzhen ' #s是一个iterable对象, it has __getitem__ () method it = ITER (s) #it是一个iterator对象, it has __next__ () and __iter__ () method print (s) print (it.__next__ ()) print (it.__next__ ()) print (it.__next__ ()) print (it.__next__ ())
The resulting output is as follows:
Software is the future of Shenzhen
Soft
Thing
Is
Deep
Cai Junsheng qq:9073204 Shenzhen
Python standard library: Built-in functions ITER (object[, Sentinel])