[0]:以前初步的了解了yield,今天在稍微深入的学习一下.
[1]首先含有yield关键字的函数就是协程,也是generator,注意,这个generator不再是函数的调用方式了,具体看一个例子
class Node(object):
def __init__(self,value):
self._left = []
self._right = []
self.value = value
def iterate(self):
for node in self._left:
for value in node.iterate():yield value
yield self.value
for node in self._right:
for value in node.iterate():yield value
def dfs(self):