title: Are integers in Python passed by value or reference?
body: <p>I wrote the following code to check if integers are passed by value or reference.</p>
  
  <pre><code>foo = 1
  
  def f(bar):
      print id(foo) == id(bar)
      bar += 1
      print foo, bar
  
  f(foo)
  </code></pre>
  
  <p>The output I get is </p>
  
  <pre><code>True
  1, 2
  </code></pre>
  
  <p>From the Python documentation, <code>id(object)</code> returns the identity of an object. In the <a href="http://en.wikipedia.org/wiki/CPython" rel="nofollow">CPython</a> implementation, this is the address of the object in memory. Since the first statement in the function body returns <code>True</code>, it means <code>foo</code> has been passed by reference, but why does the last statement print <code>1, 2</code> instead of <code>2, 2</code>?</p>