
classmethod 的存在是显然的;
staticmethod 的意义在哪里?
主要还是作用域吧,如果某个函数只在某个 class 中使用,且无关 self or cls ,则可以一用,比散落在外面强;
其实直接 self 不用也无妨;只是意义更明确,此为 class’s function 。
|
|
Refer to:
http://pythoncentral.io/difference-between-staticmethod-and-classmethod-in-python/
http://stackoverflow.com/questions/12179271/python-classmethod-and-staticmethod-for-beginner




近期评论