【发布时间】:2013-08-17 08:33:50
【问题描述】:
我正在阅读以下关于 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 的不同用法吗?
【问题讨论】: