What is the "yield" statement in a Python function?
<blockquote>
  <p><strong>Possible Duplicate:</strong><br>
  <a href="http://stackoverflow.com/questions/231767/the-python-yield-keyword-explained">The Python yield keyword explained</a>  </p>
</blockquote>



<p>Can someone explain to me what the yield statement is actually doing in this bit of code here </p>

<pre><code> def fibonacci():
     a, b = 0, 1
     while True:
         yield a
         a, b = b, a+b
</code></pre>

<p>for number in fibonacci():  # Use the generator as an iterator; print number</p>

<p>what I understand so far is, we are defining a function 'finonacci()', with no parameters?
inside the function we are defining a and b equal to 0 and 1, next, while this is true, we are yielding a. what is this actually doing? Furthermore, while yielding a? a is now equal to b, while b is now equal to a + b.
Next question, for number in fibonacci(), does this mean for every number in the function or what? I'm equally stumped on what yield and 'for number' are actually doing. Obviously I am aware that it means for every number in fibonacci() print number. Am I actually defining number without knowing it? Thanks, sorry if I'm not clear. BTW, it's for project Euler, if I knew how to program well this would be a breeze but I'm trying to learn this on the fly.</p>
