The difference between iterators and generators:
1. Iterators are created by the class object. The generator is created by a function object that contains the yield expression, or generator.
2. The principle of iterators:
(1) returned by iterable.__iter__ () iterator.
(2) The iteration value is returned by iterator.__next__ () until stopiteration.
The generic iterator implements both __iter__ () and __next__ (), returns self in __iter__ (), and returns the iteration value in __next__ () until Stopiteration
Generator principle:
(1) The generator has next (), send (), close (), throw ()
(2) Call Next ()/send (V) to execute to the next yield expression and return the yield expression result. If Send (v) executes the value of V instead of the yield expression, next () equivalent send (None)
(3) The generator does not allow return of any value.
Python: Iterator and generator summary