Dictionary and array as class vs. instance variables
<p>This is an easy way to earn some points. Please explain the following:</p>

<pre><code>class C:
    a = {}
    b = 0
    c = []

    def __init__(self):
        self.x = {}

    def d(self, k, v):
        self.x[k] = v
        self.a[k] = v;
        self.b = v
        self.c.append(v)

    def out(self, k):
        print(self.x[k], self.a[k], self.b, self.c[0])

c = C()
d = C()
c.d(1, 10)
d.d(1, 20)
c.out(1)  
d.out(1)
</code></pre>

<p>Will output the following:</p>

<pre><code>10 20 10 10
20 20 20 10
</code></pre>

<p>Why does a dictionary, a list and 'plain' variable each behave differently?</p>

<p>Edit: I was thinking the question is obvious but let me spell it in greater detail:</p>

<p>I have a class with three attributes, a, b, and c. I create two instances of the class. I then call a method that modifies these attributes for each instance. When I inspect the attributes, I find that if an attribute is a dictionary, it is shared across all instances, while if it is a 'plain' variable, it behaves as one would expect, being different for each instance.</p>
