美文网首页
Classmethod与Staticmethod

Classmethod与Staticmethod

作者: byewinter | 来源:发表于2016-12-08 10:34 被阅读0次

    1. 相同点

    使用 @classmethod 和 @staticmethod 的函数都可以直接使用 类名.方法名() 进行调用,

    不需要实例化。

    2. 不同点

    二者不同的是 @classmethod 所定义的函数中含有一个cls参数,可以直接通过cls().属性;

    cls().方法; cls().对象 来对其进行调用

    相关文章

      网友评论

          本文标题:Classmethod与Staticmethod

          本文链接:https://www.haomeiwen.com/subject/bkeppttx.html