- Definition of an Iterative object
for
There are several types of data that can be directly acting on a loop:
A class is a collection of data types, such as,,, list
tuple
, and dict
set
str
so on;
One is generator
to include the generator and yield
the generator function with the band.
These objects, which can be directly applied to for
the loop, are called iterative objects: Iterable
.
Print generator
-
- Next (g) or for n in G:print (n)
- Special: Generator and function execution flow is different. Functions are executed sequentially, encountered
return
Statement or the last line of the function statement is returned. and becomes a function of generator, at each callnext()
The time to execute, to encounteryield
Statement is returned, and is executed again from the last returnedyield
Statement to continue execution.
Python advanced-iterators and generators