标签云

微信群

扫码加入我们

WeChat QR Code


Check out the highest scoring Python question ever

2018年10月23日43分17秒

Think of yield like you would print. It sends the data elsewhere, but internal to your function will pick up exactly where it left off. You yield three times for each member of mylist, for a total of 9.

2018年10月23日43分17秒

wnnmaw I did, that's where i got part of the example. I think I may be getting it; each time it yields- it returns to the loop calling mygenerator, and when the loop calls the mygenerator generator, it resumes precisely after the previous yield statement left off and hits yield again, and returns to the loop calling the generator. For as long as yield returns a value, the loop calling it will continue. The value of i doesn't change until the loop within the createGenerator function restarts which is why i see alpha/beta/carotene 3 times each.

2018年10月23日43分17秒