OOP (Object-Oriented Programming) is a programming paradigm where you organize code into
classes and objects.
Class → A blueprint (like a template) for creating objects.
Object → An instance of a class (a real thing created from the blueprint).
Example in real life:
Class = Car (blueprint: wheels, engine, color, methods like drive, stop).
Object = my_car, your_car (specific cars created from that blueprint).
2. Python Class & Object
# Define a class
class Car:
def __init__(self, brand, color):
self.brand = brand
self.color = color
def drive(self):
print(f"{self.color} {self.brand} is driving")
# Create objects (instances)
car1 = Car("Tesla", "Red")
car2 = Car("BMW", "Black")
car1.drive() # Red Tesla is driving
car2.drive() # Black BMW is driving
__init__ Constructor (runs when you create an object).
self Refers to the current object instance.
3. OOP Principles in Python
a) Encapsulation
Bundling data (attributes) and methods (functions) together.
We use cookies to ensure you have the best browsing experience on our website. By using our site, you
acknowledge that you have read and understood our
Cookie Policy &
Privacy Policy.
Example in real life:
Car(blueprint: wheels, engine, color, methods like drive, stop).my_car,your_car(specific cars created from that blueprint).2. Python Class & Object
__init__Constructor (runs when you create an object).selfRefers to the current object instance.3. OOP Principles in Python
a) Encapsulation
Bundling data (attributes) and methods (functions) together.
b) Inheritance
One class can inherit attributes/methods from another.
c) Polymorphism
Same method name, different behavior depending on the object.
d) Abstraction
Hiding details and exposing only essential features (using
abcmodule).4. Key Features in Python OOP
In short: