๐Ÿงฑ Object-Oriented Programming (OOP) in Python

Learn the foundational concepts of OOP with practical Python examples.

๐Ÿ“Œ What is OOP?

Learn in Detail

Object-Oriented Programming is a programming paradigm based on the concept of objects. It allows structuring code in a way that is modular, reusable, and easier to maintain.

๐Ÿ”‘ Key Concepts in OOP

๐Ÿงช Example: Simple Class & Object

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

    def introduce(self):
        print(f"Hi, I'm {self.name} and I'm studying {self.course}.")

# Creating objects
s1 = Student("Ravi", "Python")
s2 = Student("Anjali", "Data Science")

s1.introduce()
s2.introduce()

๐Ÿงฌ Inheritance Example

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

    def teach(self):
        print(f"{self.name} is teaching")

class MathTeacher(Teacher):
    def teach(self):
        print(f"{self.name} is teaching Mathematics")

# Inherited behavior
m1 = MathTeacher("Suman")
m1.teach()

โš™๏ธ Why Use OOP?

๐Ÿ”— References