title: Modify Class Constant in Python
body: <p>In Python, I define a class:</p>
  
  <pre><code>class X():
      _CON = 0
  
      def __init__(self, var):
          self.y = var*self._CON 
  </code></pre>
  
  <p>Is it possible to change the constant <code>_CON</code> for an instance of <code>X</code>? For example, I attempt to do the following</p>
  
  <pre><code>X._CON = 3
  x = X(2)
  a = x.y 
  </code></pre>
  
  <p>I expect <code>_CON</code> to be changed from 0 to 3 and thus <code>self.y = var*_CON = 2*3 = 6</code>. What is the right way to do this short of creating a new class?</p>
  
  <hr>
  
  <p><strong>Edit</strong>:</p>
  
  <p>I have found the answer. My second code works. However, it changes not <code>_CON</code> of the instance <code>x</code> of the class <code>X</code> but that of the class <code>X</code> itself. The following code changes <code>_CON</code> of the instance <code>x</code> not that of the class <code>X</code>. </p>
  
  <pre><code>x = X(2)
  x._CON = 3
  x.__init__(2)
  </code></pre>