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>

<p>Python is "duck-typed", meaning it doesn't matter <em>what</em> type <code>self</code> is, as long as it provides the correct interface. Here, <code>self</code> isn't used in the body of the function, so you could pass absolutely <em>anything</em> to <code>MyClass.f</code> and it would work.</p>

<pre><code>&gt;&gt;&gt; MyClass.f(None)
'hello world'
&gt;&gt;&gt; MyClass.f(9)
'hello world'
&gt;&gt;&gt; MyClass.f("foo")
'hello world'
</code></pre>

python class