generatorex py def rxmsg()while trueitem yield print("message "itemmsg rxmsg(print(msgnext(msgsend resumes the execution and "sendsa value into the generator function msg send("hello"msg send("world"send and receive values both send and receive message can be combined together in generator alsogenerator can be closedand next(operation will generate error if it is used after closing the generatoras shown belowgeneratorex py def rxmsg()while trueitem yield yield("message ackitemmsg rxmsg(next(msgm msg send("hello"print( message ackhello next(msgm msg send("world"print( message ackworld msg close(close the generator next(msgtraceback (most recent call last)file "rectangle py"line in next(msgstopiteration return values in generator generator can return values which is displayed with exceptiongeneratorex py def rxmsg()while trueitem yield yield("message ackitemreturn "thanks(continues on next page generators