title: What happens exactly when one calls a function in Python?
body: <p>What exactly happens when a function is called in Python? Does the interpreter call a <code>__call__</code> method of an object? Then, why does the behaviour of function stay the same when I replace its <code>__call__</code> method?</p>
  
  <p>(I am working with Python 3)</p>
  
  <pre class="lang-python prettyprint-override"><code>&gt;&gt;&gt; def foo(): return 1
  &gt;&gt;&gt; foo()
  1
  &gt;&gt;&gt; foo.__call__()
  1
  &gt;&gt;&gt; foo.__call__ = lambda: 2
  &gt;&gt;&gt; foo.__call__()
  2
  &gt;&gt;&gt; foo()
  1
  </code></pre>
  
  <p>Thank you.</p>