@staticmethod
-
Python에서 @staticmethod, @classmethod, instance method,개념 정리Backend/Python 2024. 2. 16. 11:32
필자는 다른 프로젝트에서 @classmethod를 사용하는 것을 보았다. python에서는 자주 사용하지 않았는데, 이번 기회에 개념을 정리하고 SQLALchemy에 적용하기 위해 알아보았다. 먼저, method에는 크게, instance method, static method, class method가 있는데, 그 중 가장 많이 쓰이는 instance method는 사실 우리가 가장 많이 사용하고 있었다. 먼저, Shape() 라는 클래스를 하나 만들었고, 클래스 변수를 선언했다. -> 클래스 변수는 내외적으로 호출(Shape.cnt) 할 수 있다! class Shape(): # 클래스 변수 cnt = 0 def __init__(self,width,height): self.width = width se..