Abstract Base Class (abc)
say it: “AB-strakt BAYS klas” /ˈæbstrækt beɪs klæs/ or “AY-BEE-SEE” /ˌeɪˌbiˈsi/
A class you cannot use directly; it lists methods every child must write.
What is an abstract base class?
An abstract base class is a class you can't use directly. It lists methods that every child class must write, so they all share the same shape.
from abc import ABC, abstractmethod
class Shipping(ABC):
@abstractmethod
def cost(self, weight): ...
class Ground(Shipping):
def cost(self, weight):
return 5 + weight
print(Ground().cost(3)) # 8
Level: Freelancer · More Python terms at this level
Updated