码迷,mamicode.com
首页 > 编程语言 > 详细

Python @classmethod&@staticmethod 区别

时间:2015-12-25 18:40:49      阅读:196      评论:0      收藏:0      [点我收藏+]

标签:

转自Stackoverflow
@classmethod means: when this method is called, we pass the class as the first argument instead of the instance of that class (as we normally do with methods). This means you can use the class and its properties inside that method rather than a particular instance.

@staticmethod means: when this method is called, we don‘t pass an instance of the class to it (as we normally do with methods). This means you can put a function inside a class but you can‘t access the instance of that class (this is useful when your method does not use the instance).

 

Python @classmethod&@staticmethod 区别

标签:

原文地址:http://www.cnblogs.com/yaoshi/p/5076413.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!