Method / Functions - What are the differences?
bdesth.quelquechose at free.quelquepart.fr
Mon Mar 1 20:59:55 CET 2010
Michael Rudolf a écrit :
> Out of curiosity I tried this and it actually worked as expected:
>>>> class T(object):
> def f(self):
> return self.x
> At first I thought "hehe, always fun to play around with python. Might
> be useful sometimes" - but then It really confused me what I did. I
> mean: f is what we call a method, right?
Wrong. It's a function. T.f is an unbound method (in python 2.x at
least) and t.f is a bound method.
> But was is foo?
A bound method. Bound to x, of course.
> It is not a
> method and not a classmethod as it accepts no self and no cls.
Yes it does. Else how would t.foo(4) (or T.foo(4)) append 4 to x ?
> Perhaps this all does not matter,
> but now I am really confused about the
> terminology. So: what makes a method a method?
The right question is: what makes a function a method !-)
> And of what type?
I really have to put this in the wiki :-/
More information about the Python-list