title: Using a dynamically calculated 'step' inside 'xrange'
body: <p>Suppose I have:</p>
  
  <pre><code>def func(n):
      for i in range(1,100000,2*n+3):
          ...
  </code></pre>
  
  <p>It is obvious that the <code>step = 2*n+3</code> part is calculated once.</p>
  
  <p>But is this guaranteed to be the same for <code>xrange</code>?</p>
  
  <p>According to <a href="https://stackoverflow.com/a/94962/7400903">this answer</a>, <code>xrange</code> is a sequence object that evaluates lazily.</p>
  
  <p>So the question is basically - which part evaluates lazily?</p>
  
  <p>Is it only the <code>start &lt;= stop</code> part, or also the <code>step</code> part?</p>
  
  <p>I tried a simple test in order to determine the answer:</p>
  
  <pre><code>n = 1
  for a in xrange(0,100,n):
      print a
      n += 1
  </code></pre>
  
  <p>This test clearly shows that <code>n</code> is not reevaluated at every iteration.</p>
  
  <p>But I'm suspecting that perhaps the <code>n</code> inside the <code>xrange</code> expression "lives in a different scope" than that of the <code>n</code> declared before the <code>xrange</code>.</p>
  
  <p>Thank you.</p>