def task1(n
):
for i
in range(n
):
print("listening {}".format(i
))
yield None
def task2(n
):
for i
in range(n
):
print("woking {}".format(i
))
yield None
g1
=task1
(5)
g2
=task2
(5)
while True:
try:
next(g1
)
next(g2
)
except Exception
:
break
def fun():
n
=0
while True:
n
+=1
yield n
g3
=fun
()
print(g3
)
print(g3
.__next__
())
print(g3
.__next__
())
print(g3
.__next__
())
def gen():
i
=0
while i
<5:
temp
=yield i
print(temp
)
i
+=1
return "no data"
g
=gen
()
g
.send
(None)
g
.send
("zzt")
g
.send
("zzt")
g
.send
("zzt")
g
.send
("zzt")
next(g
)
next(g
)
next(g
)
next(g
)
next(g
)
转载请注明原文地址:https://tech.qufami.com/read-2428.html