Home Tutorials Python OOP Concepts Abstraction
Abstraction

Abstraction


22. Abstraction

Abstraction hides implementation details and shows only the essential features to the user. In Python, abstraction is commonly implemented using abstract base classes from the abc module.

Syntax

from abc import ABC, abstractmethod

class Shape(ABC):
    @abstractmethod
    def area(self):
        pass

Example

from abc import ABC, abstractmethod

class Vehicle(ABC):
    @abstractmethod
    def start(self):
        pass

class Bike(Vehicle):
    def start(self):
        print("Bike starts with self button")

b = Bike()
b.start()

Output

Bike starts with self button
Example

🏋️ Test Yourself With Exercises

Take our quiz on Abstraction to test your knowledge.

Browse Quizzes »