[Fixed] What does the “yield” keyword do?

Want to improve this post? Provide detailed answers to this question, including citations and an explanation of why your answer is correct. Answers without enough detail may be edited or deleted.

What is the use of the yield keyword in Python? What does it do?
For example, I’m trying to understand this code1:
def _get_child_candidates(self, distance, min_dist, max_dist):
if self._leftchild and distance – max_dist < self._median: yield self._leftchild if self._rightchild and distance + max_dist >= self._median:
yield self._rightchild

And this is the caller:
result, candidates = [], [self]
while candidates:
node = candidates.pop()
distance = node._get_dist(obj)
if distance <= max_dist and distance >= min_dist:
candidates.extend(node._get_child_candidates(distance, min_dist, max_dist))
return result

What happens when the method _get_child_candidates is called?
Is a list returned? A single element? Is it called again? When will subsequent calls stop?

1. This piece of code was written by Jochen Schulz (jrschulz), who made a great Python library for metric spaces. This is the link to the complete source: Module mspace.

[Fixed] Getting attributes of a class

I want to get the attributes of a class, say:
class MyClass():
a = “12”
b = “34”

def myfunc(self):
return self.a

using MyClass.__dict__ gives me a list of attributes and functions, and even functions like __module__ and __doc__. While MyClass().__dict__ gives me an empty dict unless I explicitly set an attribute value of that instance.
I just want the attributes, in the example above those would be: a and b