Tag:python generator
The first understanding of the Python generator function is followed by corrections and additions to the first understanding of the #python generator function, followed by corrections and additions to the # @author : Wang Zhichao #qq:1764681289 Welcome to AC def Gene (): for i in range (: ) result = yield i print (Result) a = gene () print (Next (a)) print (Next (a)) print (A.send ("BRT")) "" "f:\py\python.exe c:/users/hp/ Pycharmprojects/untitled1/test.py0none1brt2 "" "Def gene (): for i in Range (: result = yield 8 ) print (Result) A=gene () print (next ()) print (Next (a)) print (A.send ("BRT")) "" "F : \py\python.exe c:/users/hp/pycharmprojects/untitled1/test.py8none8brt8 "" "" "compares the results, outlining the call procedure of the generator function. 0, we think,x = yield a two steps to complete, the first step output a, hang; the second step, the external parameters to yield,x reference yield inside the value 1, the execution function body, to the first yield, at this time, Output yield after the content, and hang, save the state. 2. When the next () method is used again, the function is suspended from the lastStatus continues, the "next () method does not pass in the parameter to yield, the yield is none (we temporarily understand the value of yield or it holds a value of none), the result is None, execute the following function 3, to the next yield, Output yield after the content, hang, and then repeat the steps "" "
This article is from the "Hell Yo" blog, please be sure to keep this source http://hellyou.blog.51cto.com/12853112/1976888
Python Generator function Execution procedure