DEV Community

Cover image for ๐Ÿš€ Day 59 of My Data Analytics Journey !
Ramya .C
Ramya .C

Posted on

๐Ÿš€ Day 59 of My Data Analytics Journey !

๐Ÿ’ฅUnderstanding OOP in Python

Today I explored Object-Oriented Programming (OOP) in Python โ€” a very important concept in software development and data analytics.

OOP helps us write clean, reusable, and scalable code, especially when building data pipelines and machine learning projects.


๐Ÿง  What is OOP?

OOP is a programming approach where we organize code using Classes and Objects.

โœ… Class

A class is a blueprint/template for objects.

โœ… Object

An object is an instance of a class.

๐Ÿ“Œ Example

class Student:
    def __init__(self, name):
        self.name = name

s1 = Student("Ramya")
print(s1.name)
Enter fullscreen mode Exit fullscreen mode

๐Ÿ›๏ธ Four Pillars of OOP With Examples


1๏ธโƒฃ Encapsulation

Encapsulation means wrapping data (variables) and methods together, and controlling access.

class BankAccount:
    def __init__(self, balance):
        self.__balance = balance   # private variable

    def deposit(self, amount):
        self.__balance += amount

    def get_balance(self):
        return self.__balance

acc = BankAccount(5000)
acc.deposit(2000)
print(acc.get_balance())
Enter fullscreen mode Exit fullscreen mode

Why useful: Hides sensitive data like user credentials or balance.


2๏ธโƒฃ Inheritance

Inheritance allows one class to acquire properties of another class.

class Animal:
    def sound(self):
        print("Animals make sound")

class Dog(Animal):
    def sound(self):
        print("Dog barks")

d = Dog()
d.sound()
Enter fullscreen mode Exit fullscreen mode

Why useful: Helps reuse code โ€” no repeating functions.


3๏ธโƒฃ Polymorphism

Polymorphism means same function name, different behavior.

class Shape:
    def area(self):
        pass

class Square(Shape):
    def area(self):
        return "Area = side * side"

class Circle(Shape):
    def area(self):
        return "Area = ฯ€ * r * r"

print(Square().area())
print(Circle().area())
Enter fullscreen mode Exit fullscreen mode

Why useful: Makes code flexible โ€” same function works differently depending on object.


4๏ธโƒฃ Abstraction

Abstraction means hiding implementation details and showing only necessary information.

from abc import ABC, abstractmethod

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

class Car(Vehicle):
    def start(self):
        print("Car engine starts")

c = Car()
c.start()
Enter fullscreen mode Exit fullscreen mode

Why useful: Simplifies complex code, improves security.


๐Ÿ’ก Why OOP is useful in Data Analytics?

โœ… Reusable data preprocessing functions
โœ… Cleaner code for ML pipelines
โœ… Object models for datasets, features, models
โœ… Better collaboration & scalability


๐Ÿ‘ฃ My Progress Continues

Today was all about foundations, and these concepts are key for becoming a professional Data Analyst and understanding machine learning frameworks like Scikit-Learn, PyTorch, etc.

More learning every dayโ€ฆ one step at a time ๐Ÿ’ช


๐Ÿท๏ธ Tags

#python #beginners #dataanalytics #learning #oop #devto

RamyaAnalyticsJourney

Top comments (0)