Data Abstraction in Python
Data Abstraction in Python
Topperworld.in
Data Abstraction
• The process by which data and functions are defined in such a way that only
essential details can be seen and unnecessary implementations are hidden
is called Data Abstraction.
• Abstraction is really powerful for making complex tasks and codes simpler
when used in Object-Oriented Programming.
• It reduces the complexity for the user by making the relevant part
accessible and usable leaving the unnecessary code hidden.
• There are times when we do not want to give out sensitive parts of our
code implementation and this is where data abstraction can also prove to
be very functional.
• Data Abstraction in Python can be achieved through creating abstract
classes
Syntax
1. from abc import ABC
2. class ClassName(ABC):
©Topperworld
Python Programming
Example:
class AbstractClassExample(ABC):
@abstractmethod
def do_something(self):
pass
class ConcreteClassExample(AbstractClassExample):
def do_something(self):
return "Concrete class doing something!"
obj = ConcreteClassExample()
print(obj.do_something())
©Topperworld
Python Programming
Output:
❖ Points to Remember
Below are the points which we should remember about the abstract base class
in Python.
• An Abstract class can contain the both method normal and abstract
method.
• An Abstract cannot be instantiated; we cannot create objects for the
abstract class.
©Topperworld