class Car():
def __init__(self, *args, **kwargs):
self.wheels = 4
self.doors = 4
self.windows = 4
self.seats = 4
self.color = kwargs.get("color", "black")
self.price = kwargs.get("price", "$20")
def __str__(self):
return f"Car with {self.wheels} wheels"
class Convertible(Car): # 부모클래스를 상속(inherit)
def __init__(self, **kwargs): # 메소드 오버라이딩
super().__init__(**kwargs) # 확장(extend)하기 위함. super는 부모 클래스
self.time = kwargs.get("time", 10)
def take_off(self):
return "taking off"
def __str__(self):
return f"Car with no roof"
class Something(Convertible):
pass
porche = Convertible(color="green", price="$40")
print(porche)
print(porche.color)
댓글