class Car: def init(self, make, model, year, color): self.make = make self.model = model self.year = year self.color = color

def start(self):
    print(f"{self.color} {self.make} {self.model} is starting.")
    
def drive(self):
    print(f"{self.color} {self.make} {self.model} is driving.")
    
def stop(self):
    print(f"{self.color} {self.make} {self.model} is stopping.")

my_car = Car("Toyota", "Corolla", 2021, "black") my_car.start() my_car.drive() my_car.stop()

写一段类与对象代码

原文地址: http://www.cveoy.top/t/topic/HB6 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录