Python super() 함수

인스턴스

다른 클래스에서 모든 메서드와 속성을 상속받는 클래스를 생성합니다:

class Parent:
  def __init__(self, txt):
    self.message
  def printmessage(self):
    print(self.message)
class Child(Parent):
  def __init__(self, txt):
    super().__init__(txt)
x = Child("Hello, and welcome!")
x.printmessage()

실행 예제

정의와 사용 방법

super() 함수는 부모 클래스나 동생 클래스의 메서드와 속성에 대한 접근을 제공합니다.

super() 함수는 부모 클래스를 대표하는 객체를 반환합니다.

문법

super()

매개변수 값

매개변수 없음