title: Simple function that returns a number incremented by 1 on each call, without globals?
body: <p>I am trying to write a python function that on the first call, returns a 1. On the second call, returns a 2. On the third, a 3. Etc.</p>
  
  <p>Currently, I have achieved this using a global variable:</p>
  
  <pre><code>index = 0
  
  def foo():
      global index
      index += 1
      return index
  </code></pre>
  
  <p>When calling the function three times:</p>
  
  <pre><code>print(foo())
  print(foo())
  print(foo())
  </code></pre>
  
  <p>It returns the values expected:</p>
  
  <pre><code>1
  2
  3
  </code></pre>
  
  <p>But, I've read that it is bad practice to use global variables. So, I was wondering if the same result could be achieved without using globals.</p>
  
  <p>Any suggestion?</p>
  
  <p>Thank you for your help.</p>