function pointer

holger krekel pyth at devel.trillke.net
Wed Sep 11 06:27:13 EDT 2002


Christina wrote:
> Hi!
> 
> Does Python have function pointers? 

yes. Try it on the commandline prompt (type 'python'):

>>> def f(arg):
        print arg

>>> f
<function f at 0x813eeec>
>>>

and even better python has bound methods:

>>> class a:
         def f(self, arg):
             print arg

>>> a1=a()
>>> a1.f
<bound method a.f of <__main__.a instance at 0x813ee74>>
>>>

you can pass these functions and methods around and apply them
as you wish. Very powerful.

    holger




More information about the Python-list mailing list