1. Can the generator function take parameters?
Yes, the generator function supports all parameter forms, because the generator letter is one of the functions
Der Count (start=0): While True:yield startstart++
#指定从0开始的计数器
2. Can the generator function return a value with return output?
The answer is no, the generator's default return value is the generator, then you have to give him a return value this is not possible, in short, will be an error, do not believe you try.
In this case, to say, the difference between return and yield, if you read my previous blog people should understand. Return returns a value from the code block, but yield only temporarily suspends the function.
3. Can generators be nested?
def counter (start=0): While True:yield startstart+=1def repeater (): Yield 1yield 2yield from counter (ten) for Num in repeater (): If Num>100:breakprint (num)
Did you see the code? It is obvious that nested, nested syntax can be supported.
Yield from generator function
A few questions about Python builder