Write a Python program to create a class Car with attributes for make and model. Write a method full_name to return the make and model of the car concatenated as a single string.
Example 1:
Input: car = Car('Toyota', 'Camry')
Output: 'Toyota Camry'
Example 2:
Input: car = Car('Honda', 'Civic')
Output: 'Honda Civic'
Begin by defining the class Car and initialize make and model inside the __init__ function. Then, create a method full_name to return the make and model concatenated together.
class Car:
def __init__(self, make, model):
self.make = make
self.model = model
def full_name(self):
return self.make + ' ' + self.model
car = Car('Toyota', 'Camry')
print(car.full_name()) # Output: Toyota Camry
car = Car('Honda', 'Civic')
print(car.full_name()) # Output: Honda Civic
Unlock AI & Data Science treasures. Log in!