Abstraction

👋 Hi there, I am Nirmal. I am a former software engineer with a keen interest in data science and analytics domains. Besides, I love to contribute to open source and help others to understand various tech stuffs.
Search for a command to run...

👋 Hi there, I am Nirmal. I am a former software engineer with a keen interest in data science and analytics domains. Besides, I love to contribute to open source and help others to understand various tech stuffs.
No comments yet. Be the first to comment.
This series will provides the core concepts of python programming starting from variables, data types, control flow, and functions to some problem solving.
Encapsulation is an essential concept in object-oriented programming that promotes data hiding and helps maintain code integrity. In Python, although there are no strict access modifiers like in some other languages, developers can use naming conven...
Bias in Machine Learning Bias refers to the simplifying assumptions made by a model to make the target function easier to learn. High bias can lead to underfitting Represents the error introduced by approximating a real-world problem Example: A li...
When it comes to developing software applications, choosing the appropriate architectural style is a critical decision. Among the popular options are microservices and monolithic architecture. By understanding the trade-offs, readers can make well-i...

In a world where information is everywhere, businesses have tons of data at their fingertips. This data is like a goldmine waiting to be used for smart decisions. That's where Big Data analytics and Data Science come in. They're like the experts who ...

Python is a powerful tool for data professionals, largely due to its extensive collection of open-source libraries and packages. In this blog, we'll explore the fundamentals of pandas, with a special focus on its core data structures: Series and Data...

NumPy is a powerful library for numerical computing in Python, offering robust support for large, multi-dimensional arrays and an extensive collection of mathematical functions. Creating Arrays To begin using NumPy, import the library and create arra...

Abstraction allows you to create abstract classes and methods to represent common characteristics and behaviors of a group of related objects.
It focuses on hiding the internal implementation details of a class and providing a simplified interface for interacting with objects.
In Python, abstraction is achieved through abstract classes and methods using the abc module, which stands for "Abstract Base Classes".
An abstract class is a class that cannot be instantiated and acts as a blueprint for creating subclasses.
It is a common interface or application programming interface(API) for concrete subclass.
from abc import ABC, abstractmethod
#Abstract class
class Shape(ABC):
@abstractmethod
def area(self):
pass
obj = Shape()
obj.area()
Output
TypeError: Can't instantiate abstract class pen with abstract method area
In this example, Shape is an abstract class that defines an abstract methodarea(). The abstractmethod decorator indicates that these methods must be implemented in the child subclasses derived from the Shape class. Attempting to create an instance of the Shape class directly will result in a TypeError.
from abc import ABC, abstractmethod
#Abstract class
class Shape(ABC):
@abstractmethod
def area(self):
pass
class Circle(Shape):
pass
obj = Circle()
Output
TypeError: Can't instantiate abstract class pen with abstract method area
If I implement the radius() method in the child class then it executes with error-free
from abc import ABC, abstractmethod
#Abstract class
class Shape(ABC):
@abstractmethod
def area(self):
pass
'''
Circle class inherit abstract class Shape ,so it is mandatory to use
method of parent/abstract class in this child class
'''
class Circle(Shape):
def __init__(self, radius):
self.radius = radius
def area(self):
return 3.14 * self.radius**2
obj = Circle(2)
area = obj.area()
print(f"Area is : {area}")
Output :
Area is : 12.56
In this example, the Circle class is a subclass of the Shape abstract class. It provides implementations for the area() and perimeter() methods, which are required by the Shape abstract class. The Circle class can be instantiated, and its methods can be called to perform specific calculations related to circles.