Python iterator Zatan

Builder is an iterator, the iterator is not necessarily a generator

Iterables: list, tuple, dict, string, Iterable

What is an iterator?

Satisfy two conditions: 1, there iter method; 2, the next method

1 I=[1,2,3,4]
2 d=iter(I)
3 print(d)
4 print(next(d))
5 print(next(d))

 

for internal circulation three things

1, an iterative method calls iter object, returns an iterator object

2, continue to call the iterator object's next method

3, the processing exception StopIteration

 

Guess you like

Origin www.cnblogs.com/softtester/p/11583004.html