How to create an abstract class in Python?

93 views

How to create an abstract class in Python?

How to create an abstract class in Python?

solveurit24@gmail.com Changed status to publish February 13, 2025
0

Use the abc module to create abstract classes with methods that must be overridden.

from abc import ABC, abstractmethod

class AbstractClass(ABC):
    @abstractmethod
    def do_something(self):
        pass

class ImplementingClass(AbstractClass):
    def do_something(self):
        print("Implementation")

implement = ImplementingClass()
implement.do_something()  # Output: Implementation

solveurit24@gmail.com Changed status to publish February 13, 2025
0
You are viewing 1 out of 1 answers, click here to view all answers.