做哪些網(wǎng)站不受法律保護(hù)廣告設(shè)計(jì)與制作
原文:http://stackoverflow.com/questions/231767/the-python-yield-keyword-explained
注:這是一篇 stackoverflow 上一個(gè)火爆帖子的譯文
問題
Python 關(guān)鍵字 yield 的作用是什么?用來干什么的?
比如,我正在試圖理解下面的代碼:
def node._get_child_candidates(self, distance, min_dist, max_dist):if self._leftchild and distance - max_dist < self._median:yield self._leftchildif self._rightchild and distance + max_dist >= self._median:yield self._rightchild
下面的是調(diào)用:
result, candidates = list(), [self