常用装饰器

之前有一篇介绍到装饰器:https://www.cnblogs.com/yinwenbin/p/10547058.html

本篇主要是收集常用装饰器的用法(参考https://www.runoob.com/python/python-built-in-functions.html

1、classmethod

可以不需要实例化,直接类名.方法名()来调用。不需要 self 参数,但第一个参数需要是表示自身类的 cls 参数,可以来调用类的属性,类的方法,实例化对象等

2、staticmethod

返回函数的静态方法,该方法不强制要求传递参数。可以不需要实例化,直接类名.方法名()来调用

该文章有介绍classmethod和staticmethod的区别   https://www.zhihu.com/question/20021164

原文地址:https://www.cnblogs.com/yinwenbin/p/14141211.html