Understanding OOPS in Python: Classes, Objects, Encapsulation, Abstraction, Inheritance, Polymorphism, Constructors

🚀 Day 37 of Python Learning – Object-Oriented Programming System (OOPS) OOPS is one of the most powerful concepts in Python. It helps us structure our code in a more reusable and organized way. Main Principles: 🔹 Classes & Objects 🔹 Encapsulation 🔹 Abstraction 🔹 Inheritance 🔹 Polymorphism 🧱 Class: A class is a blueprint or template that defines the structure and behavior (methods & attributes) of objects. class Person: def name(self): print("My name is John") def desg(self): print("Software Trainer") p = Person() p.name() p.desg() 🎯 Object: An object is an instance of a class — it represents something real and tangible. 🔸 Encapsulation Combining data and methods into a single unit (class). Helps in data protection and reusability. 🔸 Abstraction Hiding unnecessary details and showing only essential features to the user. 🔸 Inheritance Allows a new class to use features of an existing class. 🔸 Polymorphism Means “many forms” — same method or function behaves differently based on input or context. 🏗️ Constructor in Python A constructor initializes object variables. It is automatically called when an object is created. Default Constructor class Person: def __init__(self): self.name = "Sushma" self.desg = "Trainer" def display(self): print("Name:", self.name) print("Designation:", self.desg) p = Person() p.display() Parameterized Constructor class Person: def __init__(self, name, desg): self.name = name self.desg = desg def display(self): print("Name:", self.name) print("Designation:", self.desg) p1 = Person("Pooja", "HR") p2 = Person("Harsha", "Admin") p1.display() p2.display() 💡 In short: OOPS helps to make code modular, flexible, and maintainable. #Python #OOPS #Programming #LearningJourney #Day37 #PythonDeveloper

To view or add a comment, sign in

Explore content categories