标签:pytho python object -- cep exce div from class
在python中,有yield的函数是生成器函数
def gen(para): while True: yield para print(next(gen(8))) print(next(gen(88))) print(next(gen(888))) print("--------------------------------") def gen2(): l=["This","is","genernator","!","#"] yield l print(gen2()) print(next(gen2())) print("--------------------------------") def gen3(): l=["This","is","genernator","!","#"] yield from l f=gen3() while True: try: print(next(f)) except StopIteration: break print("--------------------------------") def gen4(): while True: r=yield print(r) r=gen4() r.send(None) r.send("genernator1") r.send("genernator2")
8 88 888 -------------------------------- <generator object gen2 at 0x019BBF08> [‘This‘, ‘is‘, ‘genernator‘, ‘!‘, ‘#‘] -------------------------------- This is genernator ! # -------------------------------- genernator1 genernator2
标签:pytho python object -- cep exce div from class
原文地址:https://www.cnblogs.com/pfeiliu/p/14221262.html