1 Iterable Object
List, dict, set, tuple, file (iterate on each line) are Iterable object, but they are not iterator. But they can be converted into iterator, in two ways:
First, explicit use of the ITER () function;
Second, implicitly using the for
2 iterator
Iterator is also a iterable.
3 Generator
3.1 Kinds
There are two types of generators
3.2 Generator using yield to return the form of a function
A function that uses yield to return function values is Generator,generator is a special kind of iterator, so a function that takes iterator as a parameter can use generator.
3.3 Using generator comprehension form of generator
That is, the generator comprehension essence of the form of parentheses is a generator.
To summarize,
The relationship between the three is as follows:
Generator is Iterator,iterator is Iterable object, so the largest is the Iterable object.
Python generator iterator and Iterable object