What is the result of a yield expression in Python?

后端 未结 2 1564
北海茫月
北海茫月 2020-12-04 21:31

I know that yield turns a function into a generator, but what is the return value of the yield expression itself? For example:

def whizbang(): 
    for i in         


        
2条回答
  •  情话喂你
    2020-12-04 21:33

    This code will produce some output

    def test():
        for i in range(10):
            x = yield i
    
    t = test()
    for i in test():
        print i
    

提交回复
热议问题