Over a million developers have joined DZone.

Classmethod And Staticmethod

·

class K(object):

  # normal method (instance method)
  def method1(self):
    print 'obj.method1() becomes method1(obj)'

  # class method
  def method2(cls):
    print 'K.method2() becomes method2(K)'
  method2 = classmethod(method2)

  # static method
  def method3():
    print 'K.method3() become just method3()'
  method3 = staticmethod(method3)

obj = K()
obj.method1()
K.method2()
K.method3()
Topics:

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}