Created
December 18, 2016 09:37
-
-
Save theharveyz/5b157b1c1779f7814406f01730b742d2 to your computer and use it in GitHub Desktop.
py的@classmethod, @staticmethod装饰器对比
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
class A(object): | |
def foo(self): | |
print 'hello A' | |
@classmethod | |
def demo(cls): | |
s = cls() | |
s.foo() | |
@staticmethod | |
def demo1(): | |
s = A() | |
s.foo() | |
A.demo() # output: hello A | |
A.demo1() # output: hello A |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment