Answer the question
In order to leave comments, you need to log in
Why does the generator return an incorrect value?
There is such
def test_gen():
value = yield
end = value + 20
while True:
if value > end:
break
yield value
value += 1
mygen = test_gen()
next(mygen)
mygen.send(10)
for item in mygen:
print(item)
Answer the question
In order to leave comments, you need to log in
Because .send() not only passes the value inside the generator, but also returns the next yielded value.
mygen = test_gen()
next(mygen)
print('Send:', mygen.send(10))
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question