当前位置:首页 > 编程笔记 > 正文
已解决

Python学习笔记--Python关键字yield

来自网友在路上 180880提问 提问时间:2023-11-19 12:33:56阅读次数: 80

最佳答案 问答题库808位专家为你答疑解惑

原文:http://stackoverflow.com/questions/231767/the-python-yield-keyword-explained

注:这是一篇 stackoverflow 上一个火爆帖子的译文

问题

Python 关键字 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

下面的是调用:

result, candidates = list(), [self
查看全文

99%的人还看了

猜你感兴趣

版权申明

本文"Python学习笔记--Python关键字yield":http://eshow365.cn/6-39264-0.html 内容来自互联网,请自行判断内容的正确性。如有侵权请联系我们,立即删除!