1
|
I used to work with PHP and recently I was asking myself, whats going on with this classmethod? Python manual is very technical and very short in words so it wont help with understanding that feature. I was googling and googling and I found answer -> http://code.anjanesh.net/2007/12/python-classmethods.html. If you are lazy to click it. My explanation is shorter and below. :) in PHP (maybe not all of you know PHP, but this language is so straight forward that everybody should understand what I'm talking about) we have static variables like this:
The output will be in both cases 20. However in python we can add @classmethod decorator and thus it is possible to have output 10 and 20 respectively. Example:
Smart, ain't? |
Python的类方法
欢迎加群互相学习,共同进步。QQ群:iOS: 58099570 | Android: 572064792 | Nodejs:329118122 做人要厚道,转载请注明出处!
本文转自张昺华-sky博客园博客,原文链接:http://www.cnblogs.com/sunshine-anycall/archive/2011/07/04/2097646.html,如需转载请自行联系原作者