🐍 Introduction to OOP
Last Updated: 05 Sept 2025
OOP = Object-Oriented Programming
👉 It is a way of writing code where we organize everything into objects (real-life entities) and classes (blueprints).
- Class = Blueprint (design/template)
- Object = Real entity created from that class
Hinglish Tip 🗣: class ek "ghar ka naksha" (blueprint) hai, aur Object us naksha se banaya hua asli "ghar" hai.
✏ Why OOP?
OOP helps in:
- Reusability → Code can be reused easily.
- Organization → Code is structured and easy to understand.
- Scalability → Easy to add new features.
- Real-world mapping → Works like real objects (Car, Student, BankAccount).
Six Pillars of OOP
- Class → Blueprint
- Object → Real entity
- Polymorphism → Different behavior
- Abstraction → Hide complex logic
- Inheritance → Reuse code
- Encapsulation → Data hiding
💡 Example: Without OOP vs With OOP
❌ Without OOP
# Managing student details
student1_name = "Amit"
student1_age = 20
student2_name = "Neha"
student2_age = 22
✅ With OOP
# Using class and object
class Student:
name =""
age = 0
# Creating objects
s1 = Student()
s2 = Student()
# Assigning values
s1.name = "Amit"
s1.age = 20
s2.name = "Neha"
s2.age = 22
print(s1.name, s1.age) # Amit 20
print(s2.name, s2.age) # Neha 22
Don't worry about the implementation details, we will cover in upcoming sections.
💡 Quick Practice
- Create a class called "Person" with attributes "name" and "age".
- Create two objects of the "Person" class and assign values to their attributes.
- Print the values of the "name" and "age" attributes for each object.
- Exercises