Data-Abstraction In Python With Example

Abstraction Definition

Abstract classes are classes that contain one or more abstract methods. An abstract method is a method that is declared, but contains no implementation.

Subclasses of an abstract class in Python are not required to implement abstract methods of the parent class.

Abstract base Class(ABC)

Abstract Base Classes (ABC) ensure that derived classes implement particular methods from the base class.

abc works by marking methods of the base class as abstract, and then registering concrete classes as implementations of the abstract base.

If your code requires a particular API, you can use issubclass() or isinstance() to check an object against the abstract class.


The following Python code uses the abc module and defines an abstract base class:


 hen created.