python内置函数classmethod()的使用

2024-11-13 17:47:00

1、在方法前面加上@classmethod装饰器,表示这是一个类方法;

python内置函数classmethod()的使用

2、在方法中使用cls参数来引用类本身;

python内置函数classmethod()的使用

3、使用类名来调用方法,而不是实例。

python内置函数classmethod()的使用
猜你喜欢