title: Passing value to yield using send
body: <p>When i was googling for python <code>yield</code> i found something interesting and I never knew before i.e we can pass value to yield to change the next() value. I hope some of the new pythonist might now aware of this and I am not sure how it works too. So, If any body could explain how it works and how the behavior changes when i send a new index to yield using <code>send()</code>.</p>
  
  <p>Here is my snippets :</p>
  
  <pre><code>def print_me (count):
      i = 0
      while i &lt; count:
          val = (yield i)
          if val is not None:
              i = val
          else:
              i += 1
  
  gen = print_me(10)
  
  for i in gen:
     if i == 5:
         gen.send(8)
     else:
         print i
  </code></pre>
  
  <p>Here is my output:</p>
  
  <pre><code>0
  1
  2
  3
  4
  9
  </code></pre>