← All Exercises

Python Abstract Base Class

advancedpython~25min

Background

Abstract base classes define interfaces that subclasses must implement, enabling polymorphism and design by contract.

Problem

Create an abstract Shape class with abstract area and perimeter methods, and a Circle subclass that implements them.

Input

A radius number for the Circle subclass.

Output

The area and perimeter of the circle.

Sample tests

Sample 1

Input: Circle(radius=5)
Expected: area=78.54, perimeter=31.42

Your solution

Learning objective

Learn abstract base classes, abstractmethod decorator, and interface enforcement.