Object-Oriented Programming (OOP) is a programming paradigm that organizes code using objects and classes instead of only functions and logic. Python is a fully object-oriented language, meaning almost everything in Python is treated as an object including numbers, strings, lists, and functions.
Each Object has :
- data -> attributes (variables )
- behaviour -> methods ( functions )
Advantages of OOP :
- Better code organization
- Reusability through classes
- Easy debugging & maintenance
- Real-world problem modeling
- Supports large applications
What is a Class ?
A class is a blueprint or template used to create objects.
It defines :
what data an object will have
what actions it can perform
Example :
Python
class Student: pass What is an Object ?
An object is an instance of a class.
It represents a real entity created from the class blueprint.
Python
s1 = Student() Here , s1 is object and Student is class
Example :
Python
class Student: def study(self): print("Student is studying") s1 = Student() s1.study() #output Student is studyingOOP vs Procedural Programming :
| Procedural Programming | Object-Oriented Programming |
|---|---|
| Focus on functions | Focus on objects |
| Less reusable | Highly reusable |
| Hard to scale | Easy to scale |
| No data security | Supports data hiding |