100 days of code: Day 27 - object-oriented

Last modified on 2020-07-05

Source: 100-days-of-code.

Yesterday was a first stab at object-oriented programming in Python. Jotting down a few terms and ideas to get a grasp on this …

class Car:
    """A simple attempt to represent a car."""


    def __init__(self, manufacturer, model, year):
        """Initialize attributes to describe a car."""
        self.manufacturer = manufacturer
        self.model = model
        self.year = year
[...]
class Car:
    """A simple attempt to represent a car."""
[...]

    def get_descriptive_name(self):
        """Return a neatly formatted descriptive name."""
        long_name = f"{self.year} {self.manufacturer} {self.model}"
        return long_name.title()


my_new_car = Car('kia', 'soul', 2019)
print(my_new_car.get_descriptive_name())

Run …

$ python3 car.py 
2019 Kia Soul

Above code is from Python Crash Course by Eric Matthes. Good book!

Happy hacking!