In python does self require any object of its same type?
<p>I am reading 9.3.2. Class Objects from the python docs and I was hoping someone can clear up the following:</p>

<p>How come both scenarios return 'hello world'? The first instance I kind of understand (at least I believe I do) because self is referencing the object itself 'MyClass' and I guess passing 'm' to self in the second instance is doing the same? Does the function 'self' just need ANY reference to a 'MyClass' object?</p>

<pre><code>&gt;&gt;&gt; class MyClass:
...     """A simple example class"""
...     i = 12345
...     def f(self):
...         return 'hello world'
...
&gt;&gt;&gt; MyClass.f(MyClass)
'hello world'
&gt;&gt;&gt; m = MyClass()
&gt;&gt;&gt; MyClass.f(m)
'hello world'
</code></pre>

<pre><code>MyClass.f('what the...')
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
&lt;ipython-input-2-cca57c03fecc&gt; in &lt;module&gt;()
----&gt; 1 MyClass.f('what the...')

TypeError: unbound method f() must be called with MyClass instance as first argument (got str instance instead)

mc = MyClass()

mc.f('what?')
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
&lt;ipython-input-4-bcd3830312d3&gt; in &lt;module&gt;()
----&gt; 1 mc.f('what?')

TypeError: f() takes exactly 1 argument (2 given)
</code></pre>

<p>In the first instance, the function requires an instance of <code>MyClass</code> as the first argument.  In the second, the instance is implicitly passed.  The string argument <code>What?</code> is thus a second argument to the function which is unexpected.</p>

<p>What you may want:</p>

<pre><code>class MyClass:
    @staticmethod
    def f():
        print('hello world')

&gt;&gt;&gt; MyClass.f()
hello world

mc = MyClass()
&gt;&gt;&gt; mc.f()
hello world
</code></pre>

python class