In python, there is no real distinction between functions and methods - a method is merely a function defined in a class.
For us, this means that the function stored in the variable func
can be called like any other function. If func
refers to Foo.method1
, it's a function with 2 parameters: self
and arg
. In order to invoke func
, we simply pass a Foo
instance as the self
argument and another value as the arg
argument:
func(foo, 1)
The reason why we usually don't have to pass an argument for self
is because accessing the method through an instance automatically turns the function method1
into a bound method, where the self
argument is passed implicitly:
>>> Foo.method1 # Foo.method1 is a function
<function Foo.method1 at 0x7f9b3c7cf0d0>
>>>
>>> foo.method1 # but foo.method1 is a bound method!
<bound method Foo.method1 of <__main__.Foo object at 0x7f9b3c7dd9e8>>
For more details about functions and methods, see this question.