title: Understanding python's name binding
body: <p>I am trying to clarify for myself Python's rules for 'assigning' values 
  to variables. </p>
  
  <p>Is the following comparison between Python and C++ valid?</p>
  
  <ol>
  <li><p>In C/C++ the statement <code>int a=7</code> means, memory is allocated for an integer variable called <code>a</code> (the quantity on the <strong>LEFT</strong> of the <code>=</code> sign) 
  and only then the value 7 is stored in it.  </p></li>
  <li><p>In Python the statement <code>a=7</code> means, a <em>nameless</em> integer object with value 7 (the quantity on the <strong>RIGHT</strong> side of the <code>=</code>) is created first and stored somewhere in memory. Then the name <code>a</code> is bound to this object.</p></li>
  </ol>
  
  <p>The output of the following C++ and Python programs seem to bear this out, but I would like some feedback whether I am right.</p>
  
  <p>C++ produces different memory locations for <code>a</code> and <code>b</code>
  while <code>a</code> and <code>b</code> seem to refer to the same location in Python
  (going by the output of the id() function)</p>
  
  <p>C++ code</p>
  
  <pre><code>#include&lt;iostream&gt;
  using namespace std;
  int main(void)
  {
    int a = 7;
    int b = a; 
    cout &lt;&lt; &amp;a &lt;&lt;  "  " &lt;&lt; &amp;b &lt;&lt; endl; // a and b point to different locations in memory
    return 0;
  }
  </code></pre>
  
  <p>Output: 0x7ffff843ecb8  0x7ffff843ecbc</p>
  
  <p>Python: code</p>
  
  <pre><code>a = 7
  b = a
  print id(a), ' ' , id(b) # a and b seem to refer to the same location
  </code></pre>
  
  <p>Output: 23093448   23093448</p>