Skip to content

abstract method

An abstract method is a method in an abstract base class (ABC) that you mark as abstract rather than making it fully concrete.

You mark abstract methods with the @abstractmethod decorator from the abc module. You use them to define a common interface that all concrete subclasses must implement. If any abstract methods remain unimplemented in a subclass, Python prevents you from instantiating that class, helping you catch design mistakes early.

You can still provide a default implementation inside an abstract method. Subclasses must override it to become instantiable, but they can call super() to reuse the shared behavior.

Example

Language: Python
>>> from abc import ABC, abstractmethod

>>> class Animal(ABC):
...     @abstractmethod
...     def speak(self):
...         """Return the sound this animal makes."""
...         ...
...

>>> Animal()
Traceback (most recent call last):
    ...
TypeError: Can't instantiate abstract class Animal
⮑ without an implementation for abstract method 'speak'

>>> class Dog(Animal):
...     def speak(self):
...         return "Woof!"
...
>>> Dog().speak()
'Woof!'

To see what the decorator buys you, toggle @abstractmethod on speak() and Dog overrides speak(), then compare how Animal() and Dog().speak() behave in the Python REPL panel:

Interactive diagram — enable JavaScript to view.

The widget starts with the decorator on and no override, so the REPL raises a TypeError as soon as you call Dog(), and the status label reads “Missing speak() caught at Dog()”. Check Dog overrides speak() to make Dog concrete, and Dog().speak() returns 'Woof!'.

Now uncheck both boxes. Without the decorator, Animal() and Dog() both succeed, and Dog().speak() shows no output because the inherited speak() returns None. The status label warns “Missing speak() not caught: returns None”. The mistake slips through silently. In the animals.py panel, the struck-through @abstractmethod reminds you which version of the code you’re running.

Implementing an Interface in Python

Tutorial

Implementing Interfaces in Python: ABCs and Protocols

Learn how to implement interfaces in Python using abstract base classes, Protocols, and duck typing, and enforce method contracts cleanly.

advanced python

For additional information on related topics, take a look at the following resources:

Have a question about this? Mentor AI can show you examples, compare related terms, and point you to tutorials.


By Leodanis Pozo Ramos • Updated Oct. 21, 2026 • Reviewed by Dan Bader