2011年8月16日

【转】Python @classmethod @staticmethod

摘要: 今天读代码的时候发现Python的class定义中提及了@classmethod修饰符,然后查阅了一些材料一探究竟,先做个总结吧。在Python中提到 classmethod 就要提到 staticmethod,不是因为二者有什么关系,而是为了让用户区分以便更清楚地写代码。在C++中,我们了解直接通过类名访问的函数称为类的静态函数,即static修饰的函数,可见C++中classmethod和staticmethod是一个概念。那么python中二者有什么区别呢?先来看下二者如何在python代码中声明:classMyClass:...@classmethod # classmethod的修饰 阅读全文

posted @ 2011-08-16 09:22 ^希望^ 阅读(18848) 评论(1) 推荐(1) 编辑

导航