python: class attributes and instance attributes
<p>I'm new to python and learned that class attributes are like static data members in C++. However, I got confused after trying the following code:</p>

<pre><code>&gt;&gt;&gt; class Foo:
...     a=1
... 
&gt;&gt;&gt; f1=Foo();
&gt;&gt;&gt; f2=Foo()
&gt;&gt;&gt; f1.a
1
&gt;&gt;&gt; f1.a=5
&gt;&gt;&gt; f1.a
5
&gt;&gt;&gt; f2.a
1
</code></pre>

<p>Shouldn't f2.a also equal 5?</p>

<p>If a is defined as a list instead of an integer, the behavior is expected:</p>

<pre><code>&gt;&gt;&gt; class Foo:
...     a=[]
... 
&gt;&gt;&gt; f1=Foo();
&gt;&gt;&gt; f2=Foo()
&gt;&gt;&gt; f1.a
[]
&gt;&gt;&gt; f1.a.append(5)
&gt;&gt;&gt; f1.a
[5]
&gt;&gt;&gt; f2.a
[5]
</code></pre>

<p>I looked at
<a href="http://stackoverflow.com/questions/207000/python-difference-between-class-and-instance-attributes">Python: Difference between class and instance attributes</a>, but it doesn't answer my question.</p>

<p>Can anyone explain why the difference? Thanks</p>
