유명한 예제에서, 나는 Python 클래스에서 method, classmethod 및 staticmethod의 차이점을 배웠다.같은 Python 클래스의 메서드, 클래스 메서드, 정적 메서드 호출
지금 내가 궁금 클래스 내부 방법,출처 :
class A(object): def foo(self,x): print "executing foo(%s,%s)"%(self,x) @classmethod def class_foo(cls,x): print "executing class_foo(%s,%s)"%(cls,x) @staticmethod def static_foo(x): print "executing static_foo(%s)"%x # My Guesses def My_Question(self,x): self.foo(x) A.class_foo(x) A.static_foo(x) a=A()
What is the difference between @staticmethod and @classmethod in Python?
@classmethod
및
@staticmethod
를 호출하는 방법에 대해 설명합니다.
나는 위의 My_Question
함수에 내 추측을 넣었으므로,이 중 하나라도 잘못 되었다면 저를 수정하십시오.
당신이 가지고있는 것이 맞습니다. 모든 3에 대해 'self'를 사용하는 것도 가능합니다. – wim