# send的工作原理
# 1.send发生信息给当前停止的yield
# 2.再去调用__next__()方法,生成器接着往下指向,返回下一个yield值并停止
# 案例:
persons = [‘张三‘, ‘李四‘, ‘王五‘, ‘赵六‘, ‘钱七‘] def order(persons): for i in range(len(persons)): if i == 0: print(‘%s在面试‘ % persons[0]) else: print(‘%s叫%s在面试‘ % (name, persons[i])) print(‘%s面试完毕‘ % persons[i]) name = yield persons[i] obj = order(persons) for i in range(len(persons)): if i == 0: p = obj.__next__() else: p = obj.send(p) print(‘=============================‘)
原文地址:https://www.cnblogs.com/tingguoguoyo/p/10803713.html
时间: 2024-10-30 09:42:17