@ Introducing Python: Modern Computing in Simple Packages by Bill Lubanovic (No. 2749 / 12833)
I tried the generator. It seems to use yield that I saw for the first time in Unity.
Reference: 9.9. Generators
I've tried.
http://ideone.com/byVYbr
def my_odds(last=10, step=1):
number = 0
while number < last:
if number % 2 == 1:
yield number
number += step
alist = my_odds(10, 1)
for elem in alist:
print(elem)
result
Success time: 0.02 memory: 28384 signal:0
1
3
5
7
9
~~ 6.2.8 Generator expression ~~
@ shiracamus's Comment pointed out the difference between "generator expression" and "generator function". He also taught me about next ()
.
Thank you for the information.
Recommended Posts