Python
Python) 파이썬 상속
로픽
2018. 10. 19. 01:33
300x250
파이썬 상속
class 클래스명:
def __init__() 생성자:
def 메소드:
class 클래스명(부모클래스):
생성자:
메소드:
class Human:
def __init__(self, name, age):
self.name = name
self.age = age
def intro(self):
print("안녕!, %d살 %s입니다." % (self.age,self.name))
class Student(Human):
def __init__(self, name, age, stnum):
super().__init__(name, age)
self.stnum = stnum
def intro(self):
super().intro()
print("학번은 %d입니다." % self.stnum)
def study(self):
print("하늘천 따지 검을현 누를황")
kim = Human("김하나", 29)
kim.intro()
kim2 = Student("김둘", 29, 20181234)
kim2.intro()
kim2.study()
반응형