The generator functions are one-way communication i.e we can retrieve information from generator using next() ,
but we cannot interact with it or affect its execution while running.
First let’s understand generator.send()
generator.send()
It is used to send value to a generator that just yielded.
def double_inputs():
while True:
x = yield
yield x * 2
gen = double_inputs()
next(gen) ## run upto the first yield
print(gen.send(10)) ## goes into x variable -->20
next(gen) ## run upto the next yield
print(gen.send(6)) --> 12
next(gen) ## runs upto next yield
print(gen.send(45)) ## foes into x again -->90
next(gen) ## runs upto the next yield
print(gen.send(78)) ## goes int x again --> 156
#multithreading #object-oriented #iterators #python #python3