darkpoon 发表于 2017-4-26 07:52:49

python 静态方法

  staticmethod  或 classmethod
  一
  class C_use_staticmethod1:
  def sm(in_str):
  print in_str
  sm = staticmethod( sm )
  C_use_staticmethod1.sm("静态方法1")
  二 
class C_use_staticmethod2:
 
    @staticmetho
    def sm(in_str):
          print in_str
 
C_use_staticmethod2.sm("静态方法2")
 
如果使用 classmethod, 需要传入 cls 对象
页: [1]
查看完整版本: python 静态方法