[Python] 11-2장 매직 메소드(__str__()), self, 객체 안의 객체, 상속
__str__() 메소드 - 객체의 데이터를 문자열로 변환할 때 사용 - print(인스턴스) 출력할 때 자동적으로 호출됨 class Car: def __init__(self, speed, color, model): self.speed = speed self.color = color self.model = model def drive(self): self.speed = 60 def __str__(self): msg = "속도 = "+str(self.speed)+" 색상 = "+self.color+" 모델 = "+self.model return msg myCar = Car(0, "red", "SUV") print(myCar) # 속도 = 0 색상 = red 모델 = SUV - 참고로 __str__() 메소..