python 에서 '상속(Inheritance)' 을 배웠습니다.
아래 코드는 에러가 발생합니다.
에러발생 원인을 알고, 이를 해결할 수 있다면 본 강의를 스킵해도 무방합니다.
참고로 해결방법은 다음강의에서 나옵니다.
class Human:
def __init__(self, name):
self.name = name
def say_hello(self):
print(f"i'm {self.name} hi hello")
class Player(Human): # Human 클래스 상속
def __init__(self, name, xp=0):
# 여기서 self 는 class Player 가 만들어낸 instance 를 가리킵니다.
self.xp = xp
class Fan(Human): # Human 클래스 상속
def __init__(self, name, fav_team):
self.fav_team = fav_team
# Player 는 Human 클래스를 상속받은 클래스.
mike = Player("mike", 5)
# 부모클래스에 정의된 메서드(say_hello)를 자식클래스에서 실행하고 싶은 경우 super 를 사용해야
print(mike.say_hello())
print(mike.name)
print(mike.xp)
None
None