s = (i for i in range(10)) print(s) # <generator object <genexpr> at 0x0000028C206AB0F8>Generator object #Generator function must have yield def test(): yield 1 yield 2 yield 3 res=test() print(res) print(res.__next__())#The generator must have the next method to correctly produce output
def test(): print ( ' Starting to have children -== ' ) print ( ' Happy---- ' ) print ( ' Happy--- ' ) yield ' I ' # Don't continue the following print after yield is executed print ( ' starting to have children ' ) yield ' daughter ' print ( ' starting to have a daughter ' ) yield ' granddaughter ' res = test() print (res) print (res. __next__ ()) #The generator must have the next method to produce the output correctly # print(res.__next__())#The generator must have the next method to produce the output correctly # print(res.__next__())#The generator must have the next method to correctly generate output