class Car(object): def __init__(self, x, y): #__init__(self, name, age)就是一個很重要的建構子方法 self.wheels = x #self是一個約定成俗用關鍵字 self.doors = y self.color = "未定" def __str__(self): return f"{self.wheels}[{self.doors}]" def paint(self, any_color): self.color = any_color def mycarfunc(self): print(f"我的車是{self.wheels}輪{self.doors}門{self.color}色車") mycar=Car(4, 2) mycar.mycarfunc() print(mycar) print(mycar.doors) mycar.paint("red") print(mycar.color) mycar.mycarfunc() futurecar=Car(8,4) futurecar.mycarfunc() print(futurecar) print(futurecar.doors) futurecar.paint("silver") print(futurecar.color) futurecar.mycarfunc()