classmethod与staicmethod(Classmethod and staicmethod)

classmethod

  定义操作类,而不是操作实例的方法。classmethod方法第一个参数是类本身,而不是实例。classmethod最常见的用途是定义备选构造方法。

staticmethod

  第一个参数既不是实例,也不是类本身,它不需要是一个特殊值。其实,静态方法就是一个普通的函数,只是碰巧在类的定义体中,而不是在模块层定义。

————————

classmethod

Define the operation class, not the method of the operation instance. The first parameter of the classmethod method is the class itself, not the instance. The most common use of classmethod is to define alternative construction methods.

staticmethod

The first parameter is neither an instance nor the class itself. It does not need to be a special value. In fact, a static method is an ordinary function, which happens to be defined in the definition body of the class, not in the module layer.