Menu Close

Python 内置函数 classmethod( )

把一个方法封装成类方法。

Python 内置函数 classmethod( )

类方法隐含的第一个参数就是类,就像实例方法接收实例作为参数一样。要声明一个类方法,按惯例请使用以下方案:

语法:

classmethod() 被认为是非 Python 的,因此在较新的 Python 版本中,您可以使用 @classmethod 装饰器来定义类方法。

语法:

classmethod() 参数

classmethod() 方法采用单个参数:

  • function – 需要转换为类方法的函数

classmethod() 返回值

classmethod() 方法返回给定函数的类方法。

(草稿)

wer

Posted in Python教程