Python Practice › OOP Programs › Program 33
Car class
Create a Car class with make, model and year and a method to print them.
Output
2024 Mahindra XUV700
Approach
- Store and print the attributes.
Solution
class Car: def __init__(self, make, model, year): self.make, self.model, self.year = make, model, year def show(self): print(f"{self.year} {self.make} {self.model}") Car("Mahindra", "XUV700", 2024).show()Output
2024 Mahindra XUV700
Learn the concept
New to this topic? Read the lesson, then come back.