methods and functions, instances and classes

Tim Chase python.list at tim.thechases.com
Mon Sep 4 10:03:52 EDT 2006


> When I create an instance of a class,
> are the class's functions *copied* to create the methods?
> Or are method calls actually calls of the class's functions?
> 
> I am sure this is both obvious and FAQ,
> but I did not find a clear answer

The best way to find out is to try it:

#######################################
class Foo(object):
	def hello(self):
		return "Foo::hello"

f1 = Foo()

print f1.hello()
Foo.hello = lambda self: "new hello!"
print f1.hello()

#######################################

 From what I see of this evidence, "method calls [are] actually 
calls of the class's functions", not copied.

-tkc









More information about the Python-list mailing list