title: Inherited class variable modification in Python
body: <p>I'd like to have a child class modify a class variable that it inherits from its parent.</p>
  
  <p>I would like to do something along the lines of:</p>
  
  <pre><code>class Parent(object):
      foobar = ["hello"]
  
  class Child(Parent):
      # This does not work
      foobar = foobar.extend(["world"])
  </code></pre>
  
  <p>and ideally have:</p>
  
  <pre><code>Child.foobar = ["hello", "world"]
  </code></pre>
  
  <p>I could do:</p>
  
  <pre><code>class Child(Parent):
      def __init__(self):
        type(self).foobar.extend(["world"])
  </code></pre>
  
  <p>but then every time I instantiate an instance of Child, "world" gets appended to the list, which is undesired.  I could modify it further to:</p>
  
  <pre><code>class Child(Parent):
      def __init__(self):
        if type(self).foobar.count("world") &lt; 1:
            type(self).foobar.extend(["world"])
  </code></pre>
  
  <p>but this is still a hack because I must instantiate an instance of Child before it works.</p>
  
  <p>Is there a better way?</p>