I am learning coroutines
Why do we start coroutine in a such way next(g)
? What is the reason of this design?
Why can't we eliminate next(g)
?
My code
def grep(pattern: str):
print("Strart grep")
while True:
line = yield
if pattern in line:
print(line)
g = grep("python")
next(g)
g.send("Slow python")
g.send("Fast C++")