title: How to manage access to a mutable attribute in Python
body: <p>In Python, we can use the @property decorator to manage access to attributes. For example, if we define the class:</p>
  
  <pre><code>class C:
      def __init__(self,value):
          self._x = value
  
      @property
      def x(self):
          """I'm the 'x' property."""
          return self._x
  </code></pre>
  
  <p>we can get the value of x, but not change it:</p>
  
  <pre><code>c = C(1)
  #c.x = 4  # &lt;= this would raise an AttributeError: can't set attribute
  </code></pre>
  
  <p>However, if the attribute is of a mutable type (e.g., a list), we can set a different value for a position of the attribute:</p>
  
  <pre><code>c = C([0,0])
  c.x[0] = 1 # &lt;= this works
  </code></pre>
  
  <p>Is there a way to prevent it? If x is a list, I would like to able to change the value of positions of x only using methods of class C.</p>