<div dir="ltr">Hi,<div><br></div><div>Let's see what happens iteration by iteration. First iteration:</div><div><br></div><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<div><div style="font-family:Arial;font-size:12pt;color:rgb(0,0,0)"><div><div><font face="Arial">def fibonacci(max):  #using a generator</font><span style="font-family:arial;font-size:small;color:rgb(34,34,34)"> </span></div>
</div></div></div></blockquote><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div><div style="font-family:Arial;font-size:12pt;color:rgb(0,0,0)">
<div><div><font face="Arial">    a, b = 0, 1</font></div></div></div></div></blockquote><div> # The value of a is 0 and b is 1, easy :) </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<div><div style="font-family:Arial;font-size:12pt;color:rgb(0,0,0)"><div><div><font face="Arial">    while a < max:</font></div></div></div></div></blockquote><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<div><div style="font-family:Arial;font-size:12pt;color:rgb(0,0,0)"><div><div><font face="Arial">        yield a</font></div></div></div></div></blockquote><div># yield a (0) (yield is a keyword that is used like return but returns a generator). This value will be sent to the for iteration on the first iteration.</div>
<div><br></div><div>On the second iteration:</div><div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div style="font-family:Arial;font-size:12pt;color:rgb(0,0,0)">
<font face="Arial">        a, b = b, a+b</font>     </div></blockquote><div># a is 1 now and b is 1 (1+0) </div></div><div>And then yield a which now is 1</div><div><br></div><div>On the third iteration:</div><div><div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<div style="font-family:Arial;font-size:12pt;color:rgb(0,0,0)"><font face="Arial">        a, b = b, a+b</font>     </div></blockquote><div># a is 1 now and b is 2 (1+1) </div></div><div>And then yield a which now is 1</div>
</div><div><br></div><div><div>On the forth iteration:</div><div><div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<div style="font-family:Arial;font-size:12pt;color:rgb(0,0,0)"><font face="Arial">        a, b = b, a+b</font>     </div></blockquote><div># a is 2 now and b is 3 (2+1) </div></div><div>And then yield a which now is 2</div>
</div></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div><div style="font-family:Arial;font-size:12pt;color:rgb(0,0,0)">
<div><div><font face="Arial"></font></div><div><font face="Arial">for n in fibonacci(1000):  </font></div><div><font face="Arial">    print n,</font></div></div><div><font face="Arial">------</font></div></div></div></blockquote>
<div><br></div><div>n is the value for each iteration that the yield statement is returning. You can read the response on this thread if you want to understand more about yield, generators and iterators.</div><div><br></div>
<div>Thanks,</div></div>Raúl</div></div>