Python standard library: built-in functions iter (object [, sentinel]), itersentinel
This function returns an iteration sub-object. When the second parameter does not exist, the parameter object should be a container that supports the iteration protocol, that is, the _ iter _ () function is defined or the sequence access protocol is supported, that is, the Object Defining the _ getitem _ () function. Otherwise, a TypeError exception is returned. When the second parameter sentinel appears, the parameter object should be a callable object and the _ next _ () function is defined. When the enumerated value is equal to the Sentinel, the StopIteration exception is thrown.
Example:
# Iter () s = 'Software is the future of Shenzhen '# s is an iterable object with the _ getitem _ () method it = iter (s) # it is an iterator object, which has the _ next _ () and _ iter _ () Methods print (s) print (it. _ next _ () print (it. _ next _ () print (it. _ next _ () print (it. _ next __())
The output is as follows:
Software is the future of Shenzhen
Soft
Parts
Yes
Deep
Cai junsheng QQ: 9073204 Shenzhen