Python abstraction

In Object Oriented Programming (OOP) languages abstraction feature shows only essential attributes and hides unnecessary information. For example when you use google for signup to other website then google only sent the basic information of you to that site, and google hide details information.


  • Python abstraction with example

Python abstraction with example


from abc import ABC, abstractmethod

# Person Abstract class
class Person(ABC):

    def details(self):

# Implement Abstract class
class Customer(Person):

    def details(self):
        print("Implemented abstract method")

# Create Child class object
customer = Customer()

# Call the abstract method
  • ABC : Abstract Base classes(ABC). By default, Python does not provide abstract classes. Python comes with a module that provides the base for defining Abstract Base classes and that module name is ABC.

  • @abstractmethod : A method becomes abstract when decorated with the keyword @abstractmethod decorator.

Python abstraction video tutorial