Open ChengdongFanRain opened 8 months ago
Thanks for the suggestion @ChengdongFanRain ! The challenge with editing the text as you suggest is that functions are not covered until the next section. A better thing to do, perhaps, would be to add this example to section 5.33 and just link to that in 5.31. I will add this to my list of things to do.
Oh, and you did an excellent job in following up on this yourself to understand whatyield
does!
I haven't learned about the function: yield, so I have extremely confused about in this part. Most importantly, there are no correct output of yield shown, so I can hardly imagine what yield exactly do.
I finally understood this func after looking at this: https://stackoverflow.com/questions/231767/what-does-the-yield-keyword-do-in-python.
I believe this examples like this could help us understand better:
def yieldfunc(something): for items in something: yield items*2
for number in yieldfunc([1,2,3,4,5]): print(number)