📘 Python OOP Notes: Classes and Objects


✅ 1. What is a Class?

A class is like a blueprint for creating objects.

🔧 Real-life analogy:

A Car class is like the blueprint of a car. It defines what a car should have (like wheels, color) and what it should do (drive, brake).

You can create many cars (objects) from that one blueprint.


🔤 Syntax:

class ClassName:
    def __init__(self, param1, param2):
        self.param1 = param1
        self.param2 = param2

    def method(self):
        # do something


✅ 2. What is an Object?

An object is an instance of a class.

🔧 Real-life: If Car is the class, then my_car = Car("Red", 4) is an object (a specific car).


✅ 3. __init__() Constructor

The __init__() method is a special method that runs automatically when you create an object. It's used to initialize object data.

class Car:
    def __init__(self, brand, color):
        self.brand = brand
        self.color = color


✅ 4. Creating Objects

my_car = Car("Toyota", "Red")
print(my_car.brand)  # Output: Toyota