title: How does attribute resolution work in Python?
body: <p>Consider the following code:</p>
  
  <pre><code>class A(object):
      def do(self):
          print self.z
  
  class B(A):
      def __init__(self, y):
          self.z = y
  
  b = B(3)
  b.do()
  </code></pre>
  
  <p>Why does this work? When executing <code>b = B(3)</code>, attribute z is set. When <code>b.do()</code> is called, Python's MRO finds the <code>do</code> function in class A. But why is it able to access an attribute defined in a subclass?</p>
  
  <p>Is there a use case for this functionality? I would love an example.</p>