title: How C/C++ global variables are implemented in python?
body: <p>While i am reading through SWIG Documentation i came through these lines..</p>
  
  <p><em>C/C++ global variables are fully supported by SWIG. However, the underlying mechanism is somewhat different than you might expect due to the way that Python assignment works. When you type the following in Python<br>
  a = 3.4<br>
  "a" becomes a name for an object containing the value 3.4. If you later type<br>
  b = a<br>
  then "a" and "b" are both names for the object containing the value 3.4. Thus, there is only one object containing 3.4 and "a" and "b" are both names that refer to it. This is quite different than C where a variable name refers to a memory location in which a value is stored (and assignment copies data into that location). Because of this, there is no direct way to map variable assignment in C to variable assignment in Python.<br>
  To provide access to C global variables, SWIG creates a special object called `cvar' that is added to each SWIG generated module. Global variables are then accessed as attributes of this object.</em></p>
  
  <p>My question is what is the need for implementing in the above way. Even though we implemented in the above mentioned way object attributes are also implemented as objects.</p>
  
  <p>Please see the below python code snippet</p>
  
  <pre><code>a = 10  
  b = a  
  a is b  
  True  
  
  class sample: 
      pass   
  
  obj = sample()  
  obj.a = 10  
  obj.b = obj.a  
  obj.a is obj.b  
  True  
  </code></pre>
  
  <p>Here in both the above cases object assignment happening in the same way</p>