Data Abstraction in Python
Data Abstraction in Python:
Data Abstraction in Python is the process of hiding the real implementation of an application from the user and emphasizing only on usage of it.
Basically, Abstraction focuses on hiding the internal implementations of a process or method from the user. In this way, the user knows what he is doing but not how the work is being done.
Why Do We Need Abstraction?
- Through the process of abstraction in Python, a programmer can hide all the irrelevant data of an application to reduce complexity and increase efficiency.
from abc import ABC Class ClassName(ABC):
- In Python abstraction can be achieved using abstract class and it’s methods.
Abstract Class in Python
- A class containing one or more abstract methods is called an abstract class.
- As a property, abstract classes can have any number of abstract methods coexisting with any number of other methods.
- Abstract methods do not contain any implementation. Instead, all the implementations can be defined in the methods of sub-classes that inherit the abstract class.
- We have already discussed the syntax of abstract class above, let’s understand this by taking examples.
Area of a Square: 25
Area of a circle: 50.24
- An abstract class can have both a normal method and an abstract method
- An abstract class cannot be instantiated, ( we cannot create objects for the abstract class).