yield函数
import re
import pdb
def yield_test(n):
for i in range(n):
yield call(i)
print("step_3:i=%d\n"%i)
print("do something else..")
print("end."
def call(i):
print("step_1: input %d and call() returns %d"%(i,i*2))
return i*2
for result in yield_test(5):
print("step_2:result = %d"%(result))
https://www.cnblogs.com/ethancui/p/5656757.html
这个实践收获很不错,特别爽,人家写的也好。