title: Why calling a function inside a Python class __init__ can be both Attribute and Method?
body: <p>I am quite confused with the <strong>method</strong> and <strong>attribute</strong> of a Python class. Suppose we have a Python class like this:</p>
  <pre><code># case 1
  class Person:
  
      def __init__(self, first, last):
  
          self.first = first
          self.last = last
          self.fun()
  
      def fun(self):
          value = self.first + '---' + self.last
          self.fun = value
          return value
  
  person_1 = Person('A', 'B')  
  person_1.fun
  
  ---&gt; &quot;A---B&quot;
  </code></pre>
  <p>As we can see, in <strong>case_1</strong> we initialize an instance <code>person_1</code>. And we can get the result we want by calling <code>fun</code> as an <strong>attribute</strong>. However, if we change our code to the following, <code>fun</code> becomes a <strong>method</strong> instead.<strong>(case_2)</strong></p>
  <pre><code># case 2
  class Person:
  
      def __init__(self, first, last):
  
          self.first = first
          self.last = last
          self.fun()
  
      def fun(self):
          value = self.first + '---' + self.last
          return value
  
  person_1 = Person('A', 'B')  
  person_1.fun
  
  ---&gt; &lt;bound method Person.fun of &lt;__main__.Person object at 0x7fd4f79168d0&gt;&gt;
  </code></pre>
  <p>We still contain the init process in the class. But now <code>fun</code> becomes a <strong>method</strong> but not an <strong>attribute</strong>. <strong>(case_2)</strong></p>
  <p>If we remove the <code>self.fun()</code> in <code>init</code> but keep the <code>self.fun = value</code>, it is still a <strong>method</strong>. <strong>(case_3)</strong></p>
  <pre><code># case 3
  class Person:
  
      def __init__(self, first, last):
  
          self.first = first
          self.last = last
  
      def fun(self):
          value = self.first + '---' + self.last
          self.fun = value
          return value
  
  person_1 = Person('A', 'B')  
  person_1.fun
  
  ---&gt; &lt;bound method Person.fun of &lt;__main__.Person object at 0x7fd4f797f390&gt;&gt;
  </code></pre>
  <p>Would you mind giving me some instructions about why this happens? And what is the proper way to use the function as an attribute inside a Python Class? Thank you so much in advance!</p>