class Car: def __init__(self, make, model, year): self.make = make self.model = model self.year = year def start_engine(self): print("Engine started!") def stop_engine(self): print("Engine stopped!") def drive(self): print("Car is being driven!")
my_car = Car("Toyota", "Camry", 2022)
print(my_car.make) # Output: Toyota print(my_car.model) # Output: Camry print(my_car.year) # Output: 2022 my_car.start_engine() # Output: Engine started! my_car.drive() # Output: Car is being driven! my_car.stop_engine() # Output: Engine stopped!
Toyota Camry 2022 Engine started! Car is being driven! Engine stopped!