Python Practice › OOP Programs › Program 33

Car class

EasyOOP Programs · 33 of 48

Create a Car class with make, model and year and a method to print them.

Advertisement
Output
2024 Mahindra XUV700

Approach

  1. Store and print the attributes.

Solution

Python
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.

More oop programs

← All 48 OOP Programs

Leave a Comment