我正在阅读有关Python中生成器的以下教程: http://excess.org/article/2013/02/itergen2/
它包含以下代码:
我不理解
def running_avg():
"coroutine that accepts numbers and yields their running average"
total = float((yield))
count = 1
while True:
i = yield total / count
count += 1
total += i
我不理解
float((yield))
的含义。我认为 yield
用于从生成器中“返回”值。这是 yield
的另一种用法吗?