Back
Syntax
Study
Editor
Mode:
HTML
CSS
JavaScript
PHP
Reset
Run »
HTML / CSS / JS
def accumulator(): total = 0 while True: value = yield total if value is None: break total += value gen = accumulator() next(gen) # prime the generator print(gen.send(10)) # 10 print(gen.send(5)) # 15
Result
Open