title: How does self get bound in Python?
body: <p>How does Python bind <code>self</code> when calling functions on an object? I'm trying to understand why this:</p>
  
  <pre class="lang-py prettyprint-override"><code>class A(object):
      def __init__(self):
          self.name = 'class A'
  
      def show_name(self):
          print(self, self.name)
  
  class B(object):
      def __init__(self, a):
          self.name = 'class B'
          self.show_name = a.show_name
  
  A().show_name()
  B(A()).show_name()
  </code></pre>
  
  <p>outputs</p>
  
  <pre class="lang-py prettyprint-override"><code>(&lt;self.A object at 0x7f9d35a06e50&gt;, 'class A')
  (&lt;self.A object at 0x7f9d35a06e50&gt;, 'class A')
  </code></pre>
  
  <p><strong>Edit</strong>: How does it know that <code>show_name</code> should be given the instance of class <code>A</code> as its first (<code>self</code>) parameter, not the instance of class <code>B</code>?</p>