三种方法(静态方法、类方法、实例方法)

3个方法,即静态方法(staticmethod),类方法(classmethod)和实例方法:

class A ( object ) :
    
     def foo ( self , x ) : 实例方法
         print "executing foo(%s,%s)" % ( self , x )
 
     @ classmethod 类方法
     def class_foo ( cls , x ) :
         print "executing class_foo(%s,%s)" % ( cls , x )
 
     @ staticmethod 静态方法
     def static_foo ( x ) :
         print "executing static_foo(%s)" % x
 
a = A ( )

你可能感兴趣的:(三种方法(静态方法、类方法、实例方法))