Python – Abstraction and Inheritance – Video

Abstract classes in Python are classes that inherit from the ABC (Abstract base class). In the video below, I have solved a problem, showing how 2 classes inherit from an abstract class and implement its methods.

The abstract class is PaperProduct, with 2 abstract methods:

  • change_title()
  • change_price()

The classes, inheriting from PaperProduct are the following 2 – Newspaper and Book. Newspaper simply implements its methods, while Book has 2 additional methods:

  • add_review()
  • __str__()

At the end, this is some input and some expected output:


Expected output:

The code from the video is available here –


Tagged with: , ,