🧱 Chapter 10 – Object Oriented Programming (OOP) in Python


📘 1. What is a Class?

class Employee:  # 🏗️ This creates a new class blueprint
    name = "Prathamesh"  # 🏷️ Class attribute
    age = 17
    salary = 10000000

print(Employee.name, Employee.age, Employee.salary)

🧠 Concept:


🧍‍♂️ 2. Class vs Instance Attributes

class Employee:
    age = 17
    salary = 10000000  # 🎯 Class Attribute

prathamesh = Employee()
prathamesh.salary = 12000000  # 🧍 Instance Attribute
print(Employee.age, Employee.salary)

🧠 Concept:


🧠 3. The self Keyword – Instance Method

class Employee:
    age = 17
    salary = 10000000  # 🎯 Class Attribute

    def getInfo(self):  # 👀 'self' refers to current object
        print(f"The age is {self.age} and salary is {self.salary}")

    @staticmethod
    def greet():  # 🚫 Doesn't need 'self', doesn't touch object data
        print("Good Morning")

prathamesh = Employee()
prathamesh.salary = 12000000

Employee.greet()  # Static method (no object data used)
Employee.getInfo(prathamesh)  # Equivalent to prathamesh.getInfo()

🧠 Concept: