기록
PYTHON Class 상속 본문
class Animal:
def __init__(self):
print("생성자")
self.age =1
def liveForAyear(self):
self.age+=1
def __del__(self):
print("소멸")
class Human(Animal):
def __init__(self):
super().__init__()
self.flag_law=True
def makeWar(self):
self.flag_law=False
def __del__(self):
print("소멸")
if __name__ == '__main__':
hum=Human()
print(hum.flag_law)
print(hum.age)
hum.liveForAyear()
hum.makeWar()
print(hum.flag_law)
print(hum.age)
결과
from day03.Animal import Animal
ani = Animal()
print(ani.age)
ani.liveForAyear()
print(ani.age)
! 바이든, 빌, 오를 다중상속받아보자
class Biden:
def __init__(self):
self.idx_handsome = 10
def aging(self):
self.idx_handsome -= 1
class Bill:
def __init__(self):
self.money = 100
def breath(self):
self.money += 1
class Oh:
def __init__(self):
self.idx_intelligence=100
def chimae(self):
self.idx_intelligence -= 1
class chiwon(Biden,Bill,Oh):
def __init__(self):
Biden.__init__(self)
Bill.__init__(self)
Oh.__init__(self)
if __name__ == '__main__':
won = chiwon()
print(won.idx_handsome)
print(won.idx_intelligence)
print(won.money)
won.aging()
won.breath()
won.chimae()
print(won.idx_intelligence)
print(won.money)
print(won.idx_handsome)
결과
'PYTHON' 카테고리의 다른 글
PYQT 클릭시마다 +1 출력하게 만들기 (0) | 2023.01.02 |
---|---|
PYQT란? PYQT를 이용하여 파이썬 프로그래밍하기 (0) | 2023.01.02 |
파이썬 if 문, for문 (0) | 2022.12.30 |
구구단 짜기 (0) | 2022.12.23 |
파이썬 메서드 (0) | 2022.12.23 |
Comments