0

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++")
mascai
  • 1,373
  • 1
  • 9
  • 30
  • Does this answer your question? [Send method using generator. still trying to understand the send method and quirky behaviour](https://stackoverflow.com/questions/19892204/send-method-using-generator-still-trying-to-understand-the-send-method-and-quir) – Jan Wilamowski Apr 17 '23 at 06:10

0 Answers0