member functions in a class

Gary Herron gherron at
Thu Sep 18 09:11:41 CEST 2008

Karl Kobata wrote:
> I am new to python and am wondering. When I create a class, with ‘def’ 
> functions and if this class is instantiated say 50 times. Does this 
> mean that all the ‘def’ functions code within the class is duplicated 
> for each instance?
> Can someone give me a short and simple answer as to what happens in 
> python?
> Thanks

No code is duplicated. 50 "objects" are created. Each object has its own 
copy of the data attributes, and a reference to the (one and only) class 
object where the method attributes are located.

That's a short answer. Perhaps too short?

Gary Herron

> ------------------------------------------------------------------------
> --

More information about the Python-list mailing list