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)