<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Rajesh Vemulakonda</title>
    <description>The latest articles on DEV Community by Rajesh Vemulakonda (@vemulakonda559).</description>
    <link>https://dev.to/vemulakonda559</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4028422%2F81df2cc6-34e8-4bd9-add9-17dac778dd32.png</url>
      <title>DEV Community: Rajesh Vemulakonda</title>
      <link>https://dev.to/vemulakonda559</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/vemulakonda559"/>
    <language>en</language>
    <item>
      <title>Why Does obj.method() Automatically Receive self? A Deep Dive into Python Method Binding</title>
      <dc:creator>Rajesh Vemulakonda</dc:creator>
      <pubDate>Wed, 15 Jul 2026 04:13:27 +0000</pubDate>
      <link>https://dev.to/vemulakonda559/why-does-objmethod-automatically-receive-self-a-deep-dive-into-python-method-binding-344o</link>
      <guid>https://dev.to/vemulakonda559/why-does-objmethod-automatically-receive-self-a-deep-dive-into-python-method-binding-344o</guid>
      <description>&lt;p&gt;Every Python programmer writes:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;obj.method()&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;But have you ever wondered why Python automatically passes &lt;code&gt;self&lt;/code&gt;?&lt;/p&gt;

&lt;p&gt;While studying Python internals, I explored how method binding works, how descriptors participate in attribute access, and how Python creates bound method objects behind the scenes.&lt;/p&gt;

&lt;p&gt;This article documents that learning journey.&lt;/p&gt;

&lt;h2&gt;
  
  
  A Simple Example
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Demo&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;hello&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Hello&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="n"&gt;obj&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Demo&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;

&lt;span class="n"&gt;obj&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;hello&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We didn't pass &lt;code&gt;self&lt;/code&gt;.&lt;br&gt;
So where did it come from?&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Demo.hello(obj)&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;This produces the same result.&lt;/p&gt;

&lt;p&gt;This is the first clue that Python is doing something special behind the scenes.&lt;/p&gt;

&lt;p&gt;If &lt;code&gt;obj.hello()&lt;/code&gt; and &lt;code&gt;Demo.hello(obj)&lt;/code&gt; behave the same way, then Python must somehow be attaching &lt;code&gt;obj&lt;/code&gt; automatically when we access the method through an instance.&lt;/p&gt;

&lt;p&gt;When Python evaluates:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;obj.hello&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;it does not immediately execute the function.&lt;/p&gt;

&lt;p&gt;Instead, Python performs attribute lookup and invokes the descriptor protocol.&lt;/p&gt;

&lt;p&gt;The function object is transformed into a bound method object that already contains a reference to &lt;code&gt;obj&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;When the method is later called, &lt;code&gt;obj&lt;/code&gt; is automatically supplied as the first argument (&lt;code&gt;self&lt;/code&gt;).&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;obj.hello
     ↓
function.\_\_get\_\_(obj, Demo)
     ↓
Bound Method Created
     ↓
self Attached
     ↓
Method Executes
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Complete Notes
&lt;/h2&gt;

&lt;p&gt;This article provides a brief overview.&lt;/p&gt;

&lt;p&gt;The complete experiments, explanations, and code examples are available in the GitHub repository:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/Vemulakonda559/python-method-binding" rel="noopener noreferrer"&gt;https://github.com/Vemulakonda559/python-method-binding&lt;/a&gt;&lt;/p&gt;

</description>
      <category>python</category>
      <category>programming</category>
      <category>softwareengineering</category>
      <category>oop</category>
    </item>
  </channel>
</rss>
