#!/usr/bin/env python3
def mean_x():
s = 0.0
n = 0
while True:
s += yield
n+=1
print("s =", s, "n=", n)
print("mean = ", s/n)
x = mean_x()
next(x)
while True:
print("please input number...")
x.send(float(input()))
能写出类似的例子,就是理解协程了。
来源:CSDN
作者:未济2019
链接:https://blog.csdn.net/u011539200/article/details/81039846