super()2 super() 1. super()로 기반 클래스 초기화하기 이때는 super()를 사용해서 기반 클래스의 __init__ 메서드를 호출해줍니다. 다음과 같이 super() 뒤에 .(점)을 붙여서 메서드를 호출하는 방식입니다. super().메서드() class Person: def __init__(self): print('Person __init__') self.hello = '안녕하세요.' class Student(Person): def __init__(self): print('Student __init__') super().__init__() # super()로 기반 클래스의 __init__ 메서드 호출 self.school = '파이썬 코딩 도장' james = Student() print(james.school.. 2023. 11. 17. super() Method Introduction to the Python super super() 명령어는 상속 관계에서 대상의 부모 클래스를 반환하는 함수 구문 super(대상클래스_이름, 대상클래스_object) # Class 선언 내부에서 super를 호출하면, 인자 전달을 따로 하지 않아도 자동으로 해당 클래스의 부모 클래스를 호출해줍니다. 참조 Code class Employee: def __init__(self, name, base_pay, bonus): self.name = name self.base_pay = base_pay self.bonus = bonus def get_pay(self): return self.base_pay + self.bonusCode class SalesEmployee(Employee): .. 2023. 3. 31. 이전 1 다음