Heisenbugs vs Bohrbugs
August 22, 2023
Nullish Coalescing Assignment
September 5, 2023

August 29, 2023

How to create abstract class in python3

In the example below; "Polygon" class is the base class which has the abstract method. "Triangle" is the derived class which overrides the abstract method. All required syntax can be found below:


from abc import ABC, abstractmethod

# Defining an abstract class

class Polygon(ABC):

    @abstractmethod

    def noofsides(self):

        pass

# Define Trinangle class, from the abstract Polygon class

class Triangle(Polygon):

    # overriding abstract method

    def noofsides(self):

        print("I have 3 sides")

How to create abstract class in python3
This website uses cookies to improve your experience. By using this website you agree to our Data Privacy Statement
Read more