본문 바로가기

objectorientedprogramming3

Python 파이썬에서의 Null 객체, Null object in Python 질문 파이썬에서 null 객체를 어떻게 참조하나요? 답변 파이썬에서 'null' 객체는 싱글톤 None입니다. 무언가가 None인지 확인하려면 is 식별 연산자를 사용하세요: if foo is None: ... 2023. 5. 23.
Python __init__() 메서드와 함께 Python super() 이해하기 [중복], Understanding Python super() 질문왜 super()를 사용하나요?Base.__init__와 super().__init__를 사용하는 것에 차이가 있나요?class Base(object): def __init__(self): print "Base created" class ChildA(Base): def __init__(self): Base.__init__(self) class ChildB(Base): def __init__(self): super(ChildB, self).__init__() ChildA() ChildB() 답변super()는 기본 클래스를 명시적으로 참조하지 않아도 되어 좋을 수 있습니다. 그러나 주요 이점은 모든 종류의 다중 상속에서 발생할 수 있는 재미있는 일들입니다. 아직 이에 대해 알지 못했다면 super의 표.. 2023. 5. 6.
Python @staticmethod와 @classmethod의 차이점, Difference between @staticmethod and @classmethod 질문 데코레이트된 메소드와 @staticmethod로 데코레이트된 메소드, 그리고 @classmethod로 데코레이트된 메소드의 차이점은 무엇인가요? 답변 아래의 예제 코드를 보면서 이해해보세요: foo, class_foo, static_foo의 호출 시그니처의 차이점을 주목하세요: class A(object): def foo(self, x): print(f"executing foo({self}, {x})") @classmethod def class_foo(cls, x): print(f"executing class_foo({cls}, {x})") @staticmethod def static_foo(x): print(f"executing static_foo({x})") a = A() 아래는 객체 인스턴스가.. 2023. 5. 4.