Why there is a parameter named "self" for classmethod function?

Terry Reedy tjreedy at udel.edu
Thu May 7 00:39:28 EDT 2009


Kurt Symanzik wrote:

> 
> But you might consider decorating the method as a static method instead 
> since in your example you are not using the parameter at all.  A static 
> method would not require a parameter.
> 
> @staticmethod
> def print_hello():
>     print "hello"

Functions that refer to neither the class nor an instance thereof can 
usually be moved outside the class altogether.  Python is not Java.  I 
believe staticmethod() was mainly added because it is needed for 
.__new__(), at least in some appearances.

tjr




More information about the Python-list mailing list