In the following block of code:
def bottom():
return (yield 42)
def middle():
return (yield from bottom())
def top():
return (yield from middle())
gen = top()
value = next(gen)
print(value)
try:
value = gen.send(value*2)
except StopIteration as exc:
value = exc.value
print(value)
- What makes a return (exit 42)? Why not just return 42 and why (exit 42) in parentheses?
- What does he mean by this: "Damage return gives a value that goes up to the call stack before go back"?
- Why does he use the "exit" in the "top" and "middle" functions?
Liviu source
share