<p>If I create a class <code>A</code> as follows:</p>

<pre><code>class A:
    def __init__(self):
        self.name = 'A'
</code></pre>

<p>Inspecting the <code>__dict__</code> member looks like <code>{'name': 'A'}</code></p>

<p>If however I create a class <code>B</code>:</p>

<pre><code>class B:
    name = 'B'
</code></pre>

<p><code>__dict__</code> is empty.</p>

<p>What is the difference between the two, and why doesn't <code>name</code> show up in <code>B</code>'s <code>__dict__</code>?</p>

[{'answer_id': 35823, 'author': 'Carl Meyer', 'author_id': 3207, 'author_profile': 'https://Stackoverflow.com/users/3207', 'pm_score': 7, 'selected': True, 'text': '<p><code>B.name</code> is a class attribute, not an instance attribute.  It shows up in <code>B.__dict__</code>, but not in <code>b = B(); b.__dict__</code>.</p>\n\n<p>The distinction is obscured somewhat because when you access an attribute on an instance, the class dict is a fallback.  So in the above example, <code>b.name</code> will give you the value of <code>B.name</code>.</p>\n'}, {'answer_id': 39755, 'author': 'Tendayi Mawushe', 'author_id': 2979, 'author_profile': 'https://Stackoverflow.com/users/2979', 'pm_score': 4, 'selected': False, 'text': "<pre><code>class A:\n    def _ _init_ _(self):\n        self.name = 'A'\na = A()\n</code></pre>\n\n<p>Creates an attribute on the object instance a of type A and it can therefore be found in: <code>a.__dict__</code></p>\n\n<pre><code>class B:\n    name = 'B'\nb = B()\n</code></pre>\n\n<p>Creates an attribute on the class B and the attribute can be found in <code>B.__dict__</code> alternatively if you have an instance b of type B you can see the class level attributes in <code>b.__class__.__dict__</code></p>\n"}]
['https://Stackoverflow.com/questions/35805', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/3154/']